when library is deleted it is removed from artifacts

This commit is contained in:
nik
2010-10-14 16:09:44 +04:00
parent c1bcf9645e
commit d6a49c8ad0
7 changed files with 65 additions and 13 deletions
@@ -19,6 +19,7 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.DataKey;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.elements.PackagingElement;
import com.intellij.packaging.elements.PackagingElementType;
import com.intellij.packaging.ui.ArtifactEditor;
import com.intellij.packaging.ui.ArtifactEditorContext;
@@ -37,6 +38,8 @@ public interface ArtifactEditorEx extends ArtifactEditor, Disposable {
void removeSelectedElements();
void removePackagingElement(@NotNull String pathToParent, @NotNull PackagingElement<?> element);
LayoutTreeComponent getLayoutTreeComponent();
Artifact getArtifact();
@@ -39,14 +39,12 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactType;
import com.intellij.packaging.artifacts.ModifiableArtifact;
import com.intellij.packaging.elements.ComplexPackagingElementType;
import com.intellij.packaging.elements.CompositePackagingElement;
import com.intellij.packaging.elements.PackagingElementFactory;
import com.intellij.packaging.elements.PackagingElementType;
import com.intellij.packaging.elements.*;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.packaging.impl.elements.ArchivePackagingElement;
import com.intellij.packaging.impl.elements.ManifestFileUtil;
@@ -361,6 +359,34 @@ public class ArtifactEditorImpl implements ArtifactEditorEx {
myLayoutTreeComponent.removeSelectedElements();
}
@Override
public void removePackagingElement(@NotNull final String pathToParent, @NotNull final PackagingElement<?> element) {
myLayoutTreeComponent.editLayout(new Runnable() {
@Override
public void run() {
final CompositePackagingElement<?> parent = findCompositeElementByPath(pathToParent);
if (parent == null) return;
for (PackagingElement<?> child : parent.getChildren()) {
if (child.isEqualTo(element)) {
parent.removeChild(child);
break;
}
}
}
});
myLayoutTreeComponent.rebuildTree();
}
@Nullable
private CompositePackagingElement<?> findCompositeElementByPath(String pathToElement) {
CompositePackagingElement<?> element = getRootElement();
for (String name : StringUtil.split(pathToElement, "/")) {
element = element.findCompositeChild(name);
if (element == null) return null;
}
return element;
}
public boolean isModified() {
return myBuildOnMakeCheckBox.isSelected() != myOriginalArtifact.isBuildOnMake()
|| !Comparing.equal(getConfiguredOutputPath(), myOriginalArtifact.getOutputPath())
@@ -451,6 +477,11 @@ public class ArtifactEditorImpl implements ArtifactEditorEx {
return myValidationManager;
}
private void createUIComponents() {
myShowContentCheckBox = new ThreeStateCheckBox();
myShowSpecificContentOptionsButton = new FixedSizeButton(16);
}
private class MyDataProvider implements TypeSafeDataProvider {
public void calcData(DataKey key, DataSink sink) {
if (ARTIFACTS_EDITOR_KEY.equals(key)) {
@@ -67,23 +67,21 @@ public class ArtifactProjectStructureElement extends ProjectStructureElement {
if (packagingElement instanceof ModuleOutputPackagingElement) {
final Module module = ((ModuleOutputPackagingElement)packagingElement).findModule(myArtifactsStructureContext);
if (module != null) {
usages.add(new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, new ModuleProjectStructureElement(myContext, module),
ArtifactProjectStructureElement.this, path.getPathString(), packagingElement));
usages.add(createUsage(packagingElement, path, new ModuleProjectStructureElement(myContext, module)));
}
}
else if (packagingElement instanceof LibraryPackagingElement) {
final Library library = ((LibraryPackagingElement)packagingElement).findLibrary(myArtifactsStructureContext);
if (library != null) {
usages.add(new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, new LibraryProjectStructureElement(myContext, library),
ArtifactProjectStructureElement.this, path.getPathString(), packagingElement));
usages.add(createUsage(packagingElement, path,
new LibraryProjectStructureElement(ArtifactProjectStructureElement.this.myContext, library)));
}
}
else if (packagingElement instanceof ArtifactPackagingElement) {
final Artifact usedArtifact = ((ArtifactPackagingElement)packagingElement).findArtifact(myArtifactsStructureContext);
if (usedArtifact != null) {
final ArtifactProjectStructureElement artifactElement = myArtifactsStructureContext.getOrCreateArtifactElement(usedArtifact);
usages.add(new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, artifactElement,
ArtifactProjectStructureElement.this, path.getPathString(), packagingElement));
usages.add(createUsage(packagingElement, path, artifactElement));
}
}
return true;
@@ -92,6 +90,11 @@ public class ArtifactProjectStructureElement extends ProjectStructureElement {
return usages;
}
private UsageInArtifact createUsage(PackagingElement<?> packagingElement, PackagingElementPath path,
final ProjectStructureElement element) {
return new UsageInArtifact(myOriginalArtifact, myArtifactsStructureContext, element, this, path.getPathString(), packagingElement);
}
@Override
public String toString() {
return "artifact:" + myOriginalArtifact.getName();
@@ -81,7 +81,7 @@
<properties/>
<border type="none"/>
<children>
<component id="4157d" class="com.intellij.util.ui.ThreeStateCheckBox" binding="myShowContentCheckBox">
<component id="4157d" class="com.intellij.util.ui.ThreeStateCheckBox" binding="myShowContentCheckBox" custom-create="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
@@ -89,7 +89,7 @@
<text value="Show content of elements"/>
</properties>
</component>
<component id="d5f3d" class="com.intellij.openapi.ui.FixedSizeButton" binding="myShowSpecificContentOptionsButton">
<component id="d5f3d" class="com.intellij.openapi.ui.FixedSizeButton" binding="myShowSpecificContentOptionsButton" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
@@ -51,6 +51,11 @@ public class UsageInArtifact extends ProjectStructureElementUsage {
});
}
public void removeElement() {
final ArtifactEditorEx editor = (ArtifactEditorEx)myContext.getOrCreateEditor(myOriginalArtifact);
editor.removePackagingElement(myParentPath, myPackagingElement);
}
@Override
public String getPresentableName() {
return myOriginalArtifact.getName();
@@ -233,7 +233,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
if (usage instanceof UsageInModuleClasspath) {
rootConfigurable.removeLibraryOrderEntry(((ModuleProjectStructureElement)usage.getContainingElement()).getModule(), library);
} else if (usage instanceof UsageInArtifact) {
// TODO[nik] implement me
((UsageInArtifact)usage).removeElement();
}
}