From aef4ce013cac6eb0a8a6c26175b0a46e6e65f582 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 23 Oct 2009 13:33:31 +0400 Subject: [PATCH] manifest editing in artifacts improved: IDEADEV-40906, IDEADEV-40727, IDEADEV-40713, IDEADEV-40709, IDEADEV-40712 --- .../impl/artifacts/ArtifactModelImpl.java | 3 +- .../impl/artifacts/ArtifactUtil.java | 60 +++--- .../elements/FileCopyPackagingElement.java | 2 +- .../impl/elements/ManifestFileUtil.java | 24 ++- .../impl/ui/FileCopyPresentation.java | 9 +- .../ElementWithManifestPropertiesPanel.form | 189 +++++++++++++----- .../ElementWithManifestPropertiesPanel.java | 145 +++++++++++--- .../artifacts/ModifiableArtifactModel.java | 3 + .../intellij/packaging/ui/ArtifactEditor.java | 1 + .../packaging/ui/ArtifactEditorContext.java | 4 + .../ui/ManifestFileConfiguration.java | 22 +- .../artifacts/ArtifactEditorContextImpl.java | 8 + .../artifacts/ArtifactEditorImpl.java | 10 +- ...ArtifactsStructureConfigurableContext.java | 2 + ...factsStructureConfigurableContextImpl.java | 22 +- .../artifacts/LayoutTreeComponent.java | 3 +- .../artifacts/ManifestFilesInfo.java | 10 + 17 files changed, 380 insertions(+), 137 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java index 442af50d39b0..bd4583e8073e 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactModelImpl.java @@ -152,7 +152,8 @@ public class ArtifactModelImpl extends ArtifactModelBase implements ModifiableAr } @Nullable - public ArtifactImpl getModifiableCopy(ArtifactImpl artifact) { + public ArtifactImpl getModifiableCopy(Artifact artifact) { + //noinspection SuspiciousMethodCalls return myArtifact2ModifiableCopy.get(artifact); } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java index 83e67590d8b7..3fb3b23f6c54 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java @@ -15,8 +15,11 @@ */ package com.intellij.packaging.impl.artifacts; +import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.CompilerProjectExtension; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.SourceFolder; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; @@ -355,56 +358,55 @@ public class ArtifactUtil { return files.isEmpty() ? null : files.get(0); } - public static List findSourceFilesByOutputPath(CompositePackagingElement parent, String outputPath, - PackagingElementResolvingContext context, ArtifactType artifactType) { - outputPath = StringUtil.trimStart(outputPath, "/"); - if (outputPath.length() == 0) { + public static List findSourceFilesByOutputPath(CompositePackagingElement parent, final String outputPath, + final PackagingElementResolvingContext context, final ArtifactType artifactType) { + final String path = StringUtil.trimStart(outputPath, "/"); + if (path.length() == 0) { return Collections.emptyList(); } - int i = outputPath.indexOf('/'); - final String firstName = i != -1 ? outputPath.substring(0, i) : outputPath; - String tail = i != -1 ? outputPath.substring(i+1) : ""; + int i = path.indexOf('/'); + final String firstName = i != -1 ? path.substring(0, i) : path; + final String tail = i != -1 ? path.substring(i+1) : ""; - final List> compositeChildren = new SmartList>(); - final List fileCopies = new SmartList(); - final List dirCopies = new SmartList(); + final List result = new SmartList(); processElements(parent.getChildren(), context, artifactType, new Processor>() { public boolean process(PackagingElement element) { + //todo[nik] replace by method findSourceFile() in PackagingElement if (element instanceof CompositePackagingElement) { final CompositePackagingElement compositeElement = (CompositePackagingElement)element; if (firstName.equals(compositeElement.getName())) { - compositeChildren.add(compositeElement); + result.addAll(findSourceFilesByOutputPath(compositeElement, tail, context, artifactType)); } } else if (element instanceof FileCopyPackagingElement) { final FileCopyPackagingElement fileCopyElement = (FileCopyPackagingElement)element; - if (firstName.equals(fileCopyElement.getOutputFileName())) { - fileCopies.add(fileCopyElement); + if (firstName.equals(fileCopyElement.getOutputFileName()) && tail.length() == 0) { + ContainerUtil.addIfNotNull(fileCopyElement.findFile(), result); } } else if (element instanceof DirectoryCopyPackagingElement) { - dirCopies.add((DirectoryCopyPackagingElement)element); + final VirtualFile sourceRoot = ((DirectoryCopyPackagingElement)element).findFile(); + if (sourceRoot != null) { + ContainerUtil.addIfNotNull(sourceRoot.findFileByRelativePath(path), result); + } + } + else if (element instanceof ModuleOutputPackagingElement) { + final Module module = ((ModuleOutputPackagingElement)element).findModule(context); + final ContentEntry[] contentEntries = context.getModulesProvider().getRootModel(module).getContentEntries(); + for (ContentEntry contentEntry : contentEntries) { + for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) { + final VirtualFile sourceRoot = sourceFolder.getFile(); + if (!sourceFolder.isTestSource() && sourceRoot != null) { + ContainerUtil.addIfNotNull(sourceRoot.findFileByRelativePath(path), result); + } + } + } } return true; } }); - List result = new SmartList(); - for (CompositePackagingElement child : compositeChildren) { - result.addAll(findSourceFilesByOutputPath(child, tail, context, artifactType)); - } - if (tail.length() == 0) { - for (FileCopyPackagingElement fileCopy : fileCopies) { - ContainerUtil.addIfNotNull(fileCopy.findFile(), result); - } - } - for (DirectoryCopyPackagingElement dirCopy : dirCopies) { - final VirtualFile sourceRoot = dirCopy.findFile(); - if (sourceRoot != null) { - ContainerUtil.addIfNotNull(sourceRoot.findFileByRelativePath(outputPath), result); - } - } return result; } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java index 6513c765e76e..8835d077beec 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyPackagingElement.java @@ -58,7 +58,7 @@ public class FileCopyPackagingElement extends FileOrDirectoryCopyPackagingElemen } public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) { - return new FileCopyPresentation(myFilePath, getOutputFileName()); + return new FileCopyPresentation(myFilePath, getOutputFileName(), context); } @Override diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java index dced5f8bd21a..4bea85e59f9c 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ManifestFileUtil.java @@ -27,7 +27,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.artifacts.ArtifactType; import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElement; -import com.intellij.packaging.elements.PackagingElementFactory; import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.artifacts.ArtifactUtil; import com.intellij.packaging.impl.artifacts.PackagingElementProcessor; @@ -55,16 +54,19 @@ public class ManifestFileUtil { public static final String MANIFEST_FILE_NAME = PathUtil.getFileName(MANIFEST_PATH); public static final String MANIFEST_DIR_NAME = PathUtil.getParentPath(MANIFEST_PATH); + private ManifestFileUtil() { + } + @Nullable public static VirtualFile findManifestFile(@NotNull CompositePackagingElement root, PackagingElementResolvingContext context, ArtifactType artifactType) { return ArtifactUtil.findSourceFileByOutputPath(root, MANIFEST_PATH, context, artifactType); } - @NotNull - public static String suggestManifestFilePathAndAddElement(@NotNull CompositePackagingElement root, PackagingElementResolvingContext context, ArtifactType artifactType) { + @Nullable + public static VirtualFile suggestManifestFileDirectory(@NotNull CompositePackagingElement root, PackagingElementResolvingContext context, ArtifactType artifactType) { final VirtualFile metaInfDir = ArtifactUtil.findSourceFileByOutputPath(root, MANIFEST_DIR_NAME, context, artifactType); if (metaInfDir != null) { - return metaInfDir.getPath() + "/" + MANIFEST_FILE_NAME; + return metaInfDir; } final Ref sourceDir = Ref.create(null); @@ -89,17 +91,15 @@ public class ManifestFileUtil { }); if (!sourceDir.isNull()) { - return sourceDir.get().getPath() + "/" + MANIFEST_PATH; + return sourceDir.get(); } final Project project = context.getProject(); - final VirtualFile dir = suggestBaseDir(project, sourceFile.get()); - String filePath = dir.getPath() + "/" + MANIFEST_PATH; - PackagingElementFactory.getInstance().addFileCopy(root, MANIFEST_DIR_NAME, filePath); - return filePath; + return suggestBaseDir(project, sourceFile.get()); } + @Nullable private static VirtualFile suggestBaseDir(Project project, final @Nullable VirtualFile file) { final VirtualFile[] contentRoots = ProjectRootManager.getInstance(project).getContentRoots(); if (file == null && contentRoots.length > 0) { @@ -189,7 +189,11 @@ public class ManifestFileUtil { @NotNull public static ManifestFileConfiguration createManifestFileConfiguration(CompositePackagingElement element, final PackagingElementResolvingContext context, final ArtifactType artifactType) { - final VirtualFile manifestFile = findManifestFile(element, context, artifactType); + return createManifestFileConfiguration(findManifestFile(element, context, artifactType)); + } + + @NotNull + public static ManifestFileConfiguration createManifestFileConfiguration(@Nullable VirtualFile manifestFile) { final List classpath = new ArrayList(); String mainClass = null; final String path; diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java index ec304eb07a3a..621ae5fcfb63 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java @@ -20,6 +20,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl; +import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.ui.SimpleTextAttributes; @@ -32,10 +33,12 @@ import org.jetbrains.annotations.NotNull; public class FileCopyPresentation extends PackagingElementPresentation { private final String mySourcePath; private final String myOutputFileName; + private final ArtifactEditorContext myContext; private final VirtualFile myFile; - public FileCopyPresentation(String filePath, String outputFileName) { + public FileCopyPresentation(String filePath, String outputFileName, ArtifactEditorContext context) { myOutputFileName = outputFileName; + myContext = context; String parentPath; myFile = LocalFileSystem.getInstance().findFileByPath(filePath); @@ -61,8 +64,8 @@ public class FileCopyPresentation extends PackagingElementPresentation { } public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { - if (myFile != null && !myFile.isDirectory()) { - presentationData.setIcons(myFile.getIcon()); + if (myFile != null && !myFile.isDirectory() || myContext.isManifestFile(mySourcePath)) { + presentationData.setIcons(myFile != null ? myFile.getIcon() : PackagingElementFactoryImpl.FileCopyElementType.ICON); presentationData.addText(myOutputFileName, mainAttributes); presentationData.addText(" (" + mySourcePath + ")", commentAttributes); } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.form b/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.form index fcc32a15653a..e78575bd42f5 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.form +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.form @@ -1,6 +1,6 @@
- + @@ -8,61 +8,152 @@ - - - - - - - - - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java index da62127e768d..e5d3b18da96a 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java @@ -15,21 +15,29 @@ */ package com.intellij.packaging.impl.ui.properties; +import com.intellij.CommonBundle; import com.intellij.ide.util.TreeClassChooser; import com.intellij.ide.util.TreeClassChooserFactory; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.fileChooser.FileChooser; +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.elements.PackagingElementFactory; import com.intellij.packaging.impl.elements.CompositeElementWithManifest; import com.intellij.packaging.impl.elements.ManifestFileUtil; import com.intellij.packaging.ui.ArtifactEditorContext; -import com.intellij.packaging.ui.PackagingElementPropertiesPanel; import com.intellij.packaging.ui.ManifestFileConfiguration; +import com.intellij.packaging.ui.PackagingElementPropertiesPanel; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.search.GlobalSearchScope; @@ -40,21 +48,29 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.DocumentEvent; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.IOException; import java.util.List; /** * @author nik */ public abstract class ElementWithManifestPropertiesPanel> extends PackagingElementPropertiesPanel { + private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.ui.properties.ElementWithManifestPropertiesPanel"); private final E myElement; private final ArtifactEditorContext myContext; private JPanel myMainPanel; private TextFieldWithBrowseButton myMainClassField; private TextFieldWithBrowseButton myClasspathField; private JLabel myTitleLabel; - private TextFieldWithBrowseButton myManifestFilePathField; + private JButton myRemoveFromArtifactButton; + private JButton myCreateManifestButton; + private JButton myUseExistingManifestButton; + private JPanel myPropertiesPanel; + private JTextField myManifestPathField; + private JLabel myManifestNotFoundLabel; private ManifestFileConfiguration myManifestFileConfiguration; public ElementWithManifestPropertiesPanel(E element, final ArtifactEditorContext context) { @@ -78,46 +94,123 @@ public abstract class ElementWithManifestPropertiesPanel 0 || myMainClassField.getText().trim().length() > 0) - && myManifestFilePathField.getText().length() == 0) { - final String path = ManifestFileUtil.suggestManifestFilePathAndAddElement(myElement, myContext, myContext.getArtifactType()); - myManifestFilePathField.setText(FileUtil.toSystemDependentName(path)); + private void removeManifest() { + } + + private void createManifest() { + FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); + descriptor.setTitle("Select Directory for MANIFEST.MF file"); + final VirtualFile[] files = FileChooser.chooseFiles(myContext.getProject(), descriptor, ManifestFileUtil.suggestManifestFileDirectory(myElement, myContext, myContext.getArtifactType())); + if (files.length != 1) return; + + final Ref exc = Ref.create(null); + final VirtualFile file = new WriteAction() { + protected void run(final Result result) { + VirtualFile dir = files[0]; + try { + if (!dir.getName().equals(ManifestFileUtil.MANIFEST_DIR_NAME)) { + VirtualFile newDir = dir.findChild(ManifestFileUtil.MANIFEST_DIR_NAME); + if (newDir == null) { + newDir = dir.createChildDirectory(this, ManifestFileUtil.MANIFEST_DIR_NAME); + } + dir = newDir; + } + result.setResult(dir.createChildData(this, ManifestFileUtil.MANIFEST_FILE_NAME)); + } + catch (IOException e) { + exc.set(e); + } + } + }.execute().getResultObject(); + + final IOException exception = exc.get(); + if (exception != null) { + LOG.info(exception); + Messages.showErrorDialog(myMainPanel, exception.getMessage(), CommonBundle.getErrorTitle()); + return; } + + PackagingElementFactory.getInstance().addFileCopy(myElement, ManifestFileUtil.MANIFEST_DIR_NAME, file.getPath()); + myContext.getThisArtifactEditor().updateLayoutTree(); + updateComponents(new ManifestFileConfiguration(null, null, file.getPath())); + apply(); + } + + private void chooseManifest() { + final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { + @Override + public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { + return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || + file.getName().equalsIgnoreCase(ManifestFileUtil.MANIFEST_FILE_NAME)); + } + }; + descriptor.setTitle("Specify Path to MANIFEST.MF file"); + final VirtualFile[] files = FileChooser.chooseFiles(myContext.getProject(), descriptor); + if (files.length != 1) return; + + final String path = files[0].getPath(); + PackagingElementFactory.getInstance().addFileCopy(myElement, ManifestFileUtil.MANIFEST_DIR_NAME, path); + myContext.getThisArtifactEditor().updateLayoutTree(); + updateComponents(ManifestFileUtil.createManifestFileConfiguration(files[0])); + apply(); + } + + private void updateComponents(@NotNull ManifestFileConfiguration configuration) { + final String manifestFilePath = configuration.getManifestFilePath(); + final String card; + if (manifestFilePath != null) { + card = "properties"; + myManifestPathField.setText(FileUtil.toSystemDependentName(manifestFilePath)); + myMainClassField.setText(StringUtil.notNullize(configuration.getMainClass())); + myClasspathField.setText(StringUtil.join(configuration.getClasspath(), " ")); + } + else { + card = "buttons"; + myManifestPathField.setText(""); + } + ((CardLayout)myPropertiesPanel.getLayout()).show(myPropertiesPanel, card); } public void reset() { myTitleLabel.setText("'" + myElement.getName() + "' manifest properties:"); - myMainClassField.setText(StringUtil.notNullize(myManifestFileConfiguration.getMainClass())); - myClasspathField.setText(StringUtil.join(myManifestFileConfiguration.getClasspath(), " ")); - myManifestFilePathField.setText(FileUtil.toSystemDependentName(StringUtil.notNullize(myManifestFileConfiguration.getManifestFilePath()))); - createManifestFileIfNeeded(); + myManifestNotFoundLabel.setText("Manifest.mf file not found in '" + myElement.getName() + "'"); + final VirtualFile file = ManifestFileUtil.findManifestFile(myElement, myContext, myContext.getArtifactType()); + String path = file != null ? file.getPath() : null; + if (!Comparing.equal(path, myManifestFileConfiguration.getManifestFilePath())) { + myManifestFileConfiguration.copyFrom(ManifestFileUtil.createManifestFileConfiguration(file)); + } + updateComponents(myManifestFileConfiguration); } public boolean isModified() { @@ -128,7 +221,7 @@ public abstract class ElementWithManifestPropertiesPanel element, ArtifactType artifactType); + boolean isManifestFile(String path); + + CompositePackagingElement getRootElement(@NotNull Artifact artifact); void editLayout(@NotNull Artifact artifact, Runnable runnable); ArtifactEditor getOrCreateEditor(Artifact originalArtifact); + ArtifactEditor getThisArtifactEditor(); void selectArtifact(@NotNull Artifact artifact); diff --git a/java/compiler/openapi/src/com/intellij/packaging/ui/ManifestFileConfiguration.java b/java/compiler/openapi/src/com/intellij/packaging/ui/ManifestFileConfiguration.java index 34b38455e97f..c3d26553eae6 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/ui/ManifestFileConfiguration.java +++ b/java/compiler/openapi/src/com/intellij/packaging/ui/ManifestFileConfiguration.java @@ -15,6 +15,9 @@ */ package com.intellij.packaging.ui; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.util.List; import java.util.ArrayList; @@ -26,18 +29,25 @@ public class ManifestFileConfiguration { private String myMainClass; private String myManifestFilePath; - public ManifestFileConfiguration(ManifestFileConfiguration configuration) { - myClasspath = new ArrayList(configuration.getClasspath()); - myMainClass = configuration.getMainClass(); - myManifestFilePath = configuration.getManifestFilePath(); + public ManifestFileConfiguration(@NotNull ManifestFileConfiguration configuration) { + copyFrom(configuration); } - public ManifestFileConfiguration(List classpath, String mainClass, String manifestFilePath) { - myClasspath = classpath; + public ManifestFileConfiguration(@Nullable List classpath, @Nullable String mainClass, @Nullable String manifestFilePath) { + if (classpath != null) { + myClasspath.addAll(classpath); + } myMainClass = mainClass; myManifestFilePath = manifestFilePath; } + public void copyFrom(@NotNull ManifestFileConfiguration configuration) { + myClasspath.clear(); + myClasspath.addAll(configuration.getClasspath()); + myMainClass = configuration.getMainClass(); + myManifestFilePath = configuration.getManifestFilePath(); + } + public List getClasspath() { return myClasspath; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java index c0cae5f5ccf8..9ef57021c935 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java @@ -66,6 +66,10 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext { return myParent.getManifestFile(element, artifactType); } + public boolean isManifestFile(String path) { + return myParent.isManifestFile(path); + } + @NotNull public Project getProject() { return myParent.getProject(); @@ -83,6 +87,10 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext { return myParent.getOrCreateEditor(artifact); } + public ArtifactEditor getThisArtifactEditor() { + return myEditor; + } + public void selectArtifact(@NotNull Artifact artifact) { ProjectStructureConfigurable.getInstance(getProject()).select(artifact, true); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java index 558b487cccbb..6700b1da30ca 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorImpl.java @@ -372,6 +372,10 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { } } + public void updateLayoutTree() { + myLayoutTreeComponent.rebuildTree(); + } + public void putLibraryIntoDefaultLocation(@NotNull Library library) { myLayoutTreeComponent.putIntoDefaultLocations(Collections.singletonList(new LibrarySourceItem(library))); } @@ -393,10 +397,8 @@ public class ArtifactEditorImpl implements ArtifactEditorEx { final CompositePackagingElement oldRootElement = getRootElement(); final CompositePackagingElement newRootElement = artifactType.createRootElement(getArtifact().getName()); - if (!newRootElement.getType().equals(oldRootElement.getType())) { - ArtifactUtil.copyChildren(oldRootElement, newRootElement, myProject); - myLayoutTreeComponent.setRootElement(newRootElement); - } + ArtifactUtil.copyChildren(oldRootElement, newRootElement, myProject); + myLayoutTreeComponent.setRootElement(newRootElement); } private class MyDataProvider implements TypeSafeDataProvider { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContext.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContext.java index 3096eb3b7b41..c4f992179cc6 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContext.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContext.java @@ -34,6 +34,8 @@ public interface ArtifactsStructureConfigurableContext extends PackagingElementR @NotNull ManifestFileConfiguration getManifestFile(CompositePackagingElement element, ArtifactType artifactType); + boolean isManifestFile(String path); + CompositePackagingElement getRootElement(@NotNull Artifact artifact); void editLayout(@NotNull Artifact artifact, Runnable action); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java index 8f6dc39bdff6..6f3ade014cf3 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactsStructureConfigurableContextImpl.java @@ -77,15 +77,19 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon public CompositePackagingElement getRootElement(@NotNull Artifact artifact) { artifact = getOriginalArtifact(artifact); if (myModifiableModel != null) { - final CompositePackagingElement rootElement = myModifiableModel.getArtifactByOriginal(artifact).getRootElement(); - if (rootElement != artifact.getRootElement()) { - myModifiableRoots.put(artifact, rootElement); + final Artifact modifiableArtifact = myModifiableModel.getModifiableCopy(artifact); + if (modifiableArtifact != null) { + myModifiableRoots.put(artifact, modifiableArtifact.getRootElement()); } } - CompositePackagingElement root = myModifiableRoots.get(artifact); + return getOrCreateModifiableRootElement(artifact); + } + + private CompositePackagingElement getOrCreateModifiableRootElement(Artifact originalArtifact) { + CompositePackagingElement root = myModifiableRoots.get(originalArtifact); if (root == null) { - root = ArtifactUtil.copyFromRoot(artifact.getRootElement(), myProject); - myModifiableRoots.put(artifact, root); + root = ArtifactUtil.copyFromRoot(originalArtifact.getRootElement(), myProject); + myModifiableRoots.put(originalArtifact, root); } return root; } @@ -94,7 +98,7 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon artifact = getOriginalArtifact(artifact); final ModifiableArtifact modifiableArtifact = getModifiableArtifactModel().getOrCreateModifiableArtifact(artifact); if (modifiableArtifact.getRootElement() == artifact.getRootElement()) { - modifiableArtifact.setRootElement(getRootElement(artifact)); + modifiableArtifact.setRootElement(getOrCreateModifiableRootElement(artifact)); } action.run(); myContext.getDaemonAnalyzer().queueUpdate(new ArtifactProjectStructureElement(myContext, this, artifact)); @@ -144,6 +148,10 @@ class ArtifactsStructureConfigurableContextImpl implements ArtifactsStructureCon return myManifestFilesInfo.getManifestFile(element, artifactType, this); } + public boolean isManifestFile(String path) { + return myManifestFilesInfo.isManifestFile(path); + } + public ManifestFilesInfo getManifestFilesInfo() { return myManifestFilesInfo; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java index c1810e4e7571..76c83417efe9 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/LayoutTreeComponent.java @@ -130,7 +130,7 @@ public class LayoutTreeComponent implements DnDTarget, Disposable { public void updatePropertiesPanel(final boolean force) { final PackagingElement selected = getSelection().getElementIfSingle(); - if (force || Comparing.equal(selected, mySelectedElementInfo.myElement)) { + if (!force && Comparing.equal(selected, mySelectedElementInfo.myElement)) { return; } mySelectedElementInfo.save(); @@ -504,6 +504,7 @@ public class LayoutTreeComponent implements DnDTarget, Disposable { else { cardLayout.show(myPropertiesPanelWrapper, EMPTY_CARD); } + myPropertiesPanelWrapper.repaint(); } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ManifestFilesInfo.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ManifestFilesInfo.java index f937d26b2975..5a643cfbc110 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ManifestFilesInfo.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ManifestFilesInfo.java @@ -24,6 +24,7 @@ import com.intellij.packaging.elements.CompositePackagingElement; import com.intellij.packaging.elements.PackagingElementResolvingContext; import com.intellij.packaging.impl.elements.ManifestFileUtil; import com.intellij.packaging.ui.ManifestFileConfiguration; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.Map; @@ -79,4 +80,13 @@ public class ManifestFilesInfo { myManifestFiles.clear(); myOriginalManifestFiles.clear(); } + + public boolean isManifestFile(@NotNull String path) { + for (ManifestFileConfiguration configuration : myManifestFiles.values()) { + if (path.equals(configuration.getManifestFilePath())) { + return true; + } + } + return false; + } } \ No newline at end of file