mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
improved handling of artifacts with unknown elements
This commit is contained in:
+4
-44
@@ -16,14 +16,10 @@
|
||||
package com.intellij.openapi.roots.ui.configuration.artifacts;
|
||||
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectStructureElementConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -33,19 +29,13 @@ import java.awt.event.ActionListener;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ArtifactConfigurable extends ProjectStructureElementConfigurable<Artifact> {
|
||||
private final Artifact myOriginalArtifact;
|
||||
private final ArtifactsStructureConfigurableContext myArtifactsStructureContext;
|
||||
public class ArtifactConfigurable extends ArtifactConfigurableBase {
|
||||
private final ArtifactEditorImpl myEditor;
|
||||
private boolean myIsInUpdateName;
|
||||
private final ProjectStructureElement myProjectStructureElement;
|
||||
|
||||
public ArtifactConfigurable(Artifact originalArtifact, ArtifactsStructureConfigurableContextImpl artifactsStructureContext, final Runnable updateTree) {
|
||||
super(true, updateTree);
|
||||
myOriginalArtifact = originalArtifact;
|
||||
myArtifactsStructureContext = artifactsStructureContext;
|
||||
super(originalArtifact, artifactsStructureContext, updateTree, true);
|
||||
myEditor = artifactsStructureContext.getOrCreateEditor(originalArtifact);
|
||||
myProjectStructureElement = myArtifactsStructureContext.getOrCreateArtifactElement(myOriginalArtifact);
|
||||
}
|
||||
|
||||
public void setDisplayName(String name) {
|
||||
@@ -56,11 +46,6 @@ public class ArtifactConfigurable extends ProjectStructureElementConfigurable<Ar
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectStructureElement getProjectStructureElement() {
|
||||
return myProjectStructureElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName() {
|
||||
myIsInUpdateName = true;
|
||||
@@ -72,35 +57,10 @@ public class ArtifactConfigurable extends ProjectStructureElementConfigurable<Ar
|
||||
}
|
||||
}
|
||||
|
||||
private Artifact getArtifact() {
|
||||
return myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact);
|
||||
}
|
||||
|
||||
public Artifact getEditableObject() {
|
||||
return getArtifact();
|
||||
}
|
||||
|
||||
public String getBannerSlogan() {
|
||||
return ProjectBundle.message("banner.slogan.artifact.0", getDisplayName());
|
||||
}
|
||||
|
||||
public JComponent createOptionsPanel() {
|
||||
return myEditor.createMainComponent();
|
||||
}
|
||||
|
||||
@Nls
|
||||
public String getDisplayName() {
|
||||
return getArtifact().getName();
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return getArtifact().getArtifactType().getIcon();
|
||||
}
|
||||
|
||||
public String getHelpTopic() {
|
||||
return myEditor.getHelpTopic();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createTopRightComponent() {
|
||||
final ComboBox artifactTypeBox = new ComboBox();
|
||||
@@ -137,7 +97,7 @@ public class ArtifactConfigurable extends ProjectStructureElementConfigurable<Ar
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
public void disposeUIResources() {
|
||||
public String getHelpTopic() {
|
||||
return myEditor.getHelpTopic();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.artifacts;
|
||||
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectStructureElementConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class ArtifactConfigurableBase extends ProjectStructureElementConfigurable<Artifact> {
|
||||
protected final Artifact myOriginalArtifact;
|
||||
protected final ArtifactsStructureConfigurableContext myArtifactsStructureContext;
|
||||
protected final ProjectStructureElement myProjectStructureElement;
|
||||
|
||||
public ArtifactConfigurableBase(Artifact originalArtifact,
|
||||
ArtifactsStructureConfigurableContextImpl artifactsStructureContext,
|
||||
Runnable updateTree,
|
||||
final boolean nameEditable) {
|
||||
super(nameEditable, updateTree);
|
||||
myOriginalArtifact = originalArtifact;
|
||||
myArtifactsStructureContext = artifactsStructureContext;
|
||||
myProjectStructureElement = myArtifactsStructureContext.getOrCreateArtifactElement(myOriginalArtifact);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectStructureElement getProjectStructureElement() {
|
||||
return myProjectStructureElement;
|
||||
}
|
||||
|
||||
protected Artifact getArtifact() {
|
||||
return myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact);
|
||||
}
|
||||
|
||||
public Artifact getEditableObject() {
|
||||
return getArtifact();
|
||||
}
|
||||
|
||||
public String getBannerSlogan() {
|
||||
return ProjectBundle.message("banner.slogan.artifact.0", getDisplayName());
|
||||
}
|
||||
|
||||
@Nls
|
||||
public String getDisplayName() {
|
||||
return getArtifact().getName();
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return getArtifact().getArtifactType().getIcon();
|
||||
}
|
||||
|
||||
public void disposeUIResources() {
|
||||
}
|
||||
}
|
||||
+12
-3
@@ -35,8 +35,10 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.*;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.ui.MasterDetailsState;
|
||||
import com.intellij.openapi.ui.MasterDetailsStateService;
|
||||
import com.intellij.openapi.ui.NamedConfigurable;
|
||||
import com.intellij.packaging.artifacts.*;
|
||||
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
|
||||
import com.intellij.packaging.impl.artifacts.InvalidArtifact;
|
||||
import com.intellij.packaging.impl.artifacts.PackagingElementPath;
|
||||
import com.intellij.packaging.impl.artifacts.PackagingElementProcessor;
|
||||
import com.intellij.packaging.impl.elements.LibraryElementType;
|
||||
@@ -177,7 +179,7 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
|
||||
protected void loadTree() {
|
||||
myTree.setRootVisible(false);
|
||||
myTree.setShowsRootHandles(false);
|
||||
for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getArtifacts()) {
|
||||
for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getAllArtifactsIncludingInvalid()) {
|
||||
addArtifactNode(artifact);
|
||||
}
|
||||
}
|
||||
@@ -186,14 +188,21 @@ public class ArtifactsStructureConfigurable extends BaseStructureConfigurable {
|
||||
@Override
|
||||
protected Collection<? extends ProjectStructureElement> getProjectStructureElements() {
|
||||
final List<ProjectStructureElement> elements = new ArrayList<ProjectStructureElement>();
|
||||
for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getArtifacts()) {
|
||||
for (Artifact artifact : myPackagingEditorContext.getArtifactModel().getAllArtifactsIncludingInvalid()) {
|
||||
elements.add(myPackagingEditorContext.getOrCreateArtifactElement(artifact));
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
private MyNode addArtifactNode(final Artifact artifact) {
|
||||
final MyNode node = new MyNode(new ArtifactConfigurable(artifact, myPackagingEditorContext, TREE_UPDATER));
|
||||
final NamedConfigurable<Artifact> configurable;
|
||||
if (artifact instanceof InvalidArtifact) {
|
||||
configurable = new InvalidArtifactConfigurable((InvalidArtifact)artifact, myPackagingEditorContext, TREE_UPDATER);
|
||||
}
|
||||
else {
|
||||
configurable = new ArtifactConfigurable(artifact, myPackagingEditorContext, TREE_UPDATER);
|
||||
}
|
||||
final MyNode node = new MyNode(configurable);
|
||||
addNode(node, myRoot);
|
||||
return node;
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.roots.ui.configuration.artifacts.InvalidArtifactConfigurable.InvalidArtifactComponent">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="b67c4">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="2bf31" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Cannot load artifact"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b6c83" class="javax.swing.JLabel" binding="myIconLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f350" class="com.intellij.openapi.ui.ex.MultiLineLabel" binding="myDescriptionLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.artifacts;
|
||||
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.ui.ex.MultiLineLabel;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.packaging.impl.artifacts.InvalidArtifact;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class InvalidArtifactConfigurable extends ArtifactConfigurableBase {
|
||||
private String myErrorMessage;
|
||||
|
||||
public InvalidArtifactConfigurable(InvalidArtifact originalArtifact,
|
||||
ArtifactsStructureConfigurableContextImpl artifactsStructureContext,
|
||||
Runnable updateTree) {
|
||||
super(originalArtifact, artifactsStructureContext, updateTree, false);
|
||||
myErrorMessage = originalArtifact.getErrorMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new InvalidArtifactComponent(myErrorMessage).myMainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpTopic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
private static class InvalidArtifactComponent {
|
||||
private JPanel myMainPanel;
|
||||
private MultiLineLabel myDescriptionLabel;
|
||||
private JLabel myIconLabel;
|
||||
|
||||
private InvalidArtifactComponent(String errorMessage) {
|
||||
myIconLabel.setIcon(IconLoader.getIcon("/runConfigurations/configurationWarning.png"));
|
||||
myDescriptionLabel.setText(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user