2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
;
18 import com
.intellij
.openapi
.ui
.VerticalFlowLayout
;
19 import com
.intellij
.packaging
.artifacts
.Artifact
;
20 import com
.intellij
.packaging
.artifacts
.ArtifactProperties
;
21 import com
.intellij
.packaging
.artifacts
.ArtifactPropertiesProvider
;
22 import com
.intellij
.packaging
.artifacts
.ModifiableArtifact
;
23 import com
.intellij
.packaging
.impl
.artifacts
.ArtifactUtil
;
24 import com
.intellij
.packaging
.ui
.ArtifactEditorContext
;
25 import com
.intellij
.packaging
.ui
.ArtifactPropertiesEditor
;
26 import com
.intellij
.ui
.TabbedPaneWrapper
;
34 public class ArtifactPropertiesEditors
{
35 private static final List
<String
> STANDARD_TABS_ORDER
= Arrays
.asList(
36 ArtifactPropertiesEditor
.VALIDATION_TAB
, ArtifactPropertiesEditor
.PRE_PROCESSING_TAB
, ArtifactPropertiesEditor
.POST_PROCESSING_TAB
38 private Map
<String
, JPanel
> myMainPanels
;
39 private final ArtifactEditorContext myContext
;
40 private final Artifact myOriginalArtifact
;
41 private List
<PropertiesEditorInfo
> myEditors
;
43 public ArtifactPropertiesEditors(ArtifactEditorContext context
, Artifact originalArtifact
, Artifact artifact
) {
45 myOriginalArtifact
= originalArtifact
;
46 myMainPanels
= new HashMap
<String
, JPanel
>();
47 myEditors
= new ArrayList
<PropertiesEditorInfo
>();
48 for (ArtifactPropertiesProvider provider
: artifact
.getPropertiesProviders()) {
49 final PropertiesEditorInfo editorInfo
= new PropertiesEditorInfo(provider
);
50 myEditors
.add(editorInfo
);
51 final String tabName
= editorInfo
.myEditor
.getTabName();
52 JPanel panel
= myMainPanels
.get(tabName
);
54 panel
= new JPanel(new VerticalFlowLayout());
55 myMainPanels
.put(tabName
, panel
);
57 panel
.add(editorInfo
.myEditor
.createComponent());
61 public void applyProperties() {
62 for (PropertiesEditorInfo editor
: myEditors
) {
63 if (editor
.isModified()) {
64 editor
.applyProperties();
69 public void addTabs(TabbedPaneWrapper tabbedPane
) {
70 List
<String
> sortedTabs
= new ArrayList
<String
>(myMainPanels
.keySet());
71 Collections
.sort(sortedTabs
, new Comparator
<String
>() {
72 public int compare(String o1
, String o2
) {
73 int i1
= STANDARD_TABS_ORDER
.indexOf(o1
);
74 if (i1
== -1) i1
= STANDARD_TABS_ORDER
.size();
75 int i2
= STANDARD_TABS_ORDER
.indexOf(o2
);
76 if (i2
== -1) i2
= STANDARD_TABS_ORDER
.size();
80 return o1
.compareTo(o2
);
83 for (String tab
: sortedTabs
) {
84 tabbedPane
.addTab(tab
, myMainPanels
.get(tab
));
88 public boolean isModified() {
89 for (PropertiesEditorInfo editor
: myEditors
) {
90 if (editor
.isModified()) {
97 public void removeTabs(TabbedPaneWrapper tabbedPane
) {
98 for (String tabName
: myMainPanels
.keySet()) {
99 for (int i
= 0; i
< tabbedPane
.getTabCount(); i
++) {
100 if (tabName
.equals(tabbedPane
.getTitleAt(i
))) {
101 tabbedPane
.removeTabAt(i
);
108 private class PropertiesEditorInfo
{
109 private ArtifactPropertiesEditor myEditor
;
110 private ArtifactProperties
<?
> myProperties
;
111 private ArtifactPropertiesProvider myProvider
;
113 private PropertiesEditorInfo(ArtifactPropertiesProvider provider
) {
114 myProvider
= provider
;
115 myProperties
= provider
.createProperties(myOriginalArtifact
.getArtifactType());
116 final ArtifactProperties
<?
> originalProperties
= myOriginalArtifact
.getProperties(provider
);
117 if (originalProperties
!= null) {
118 ArtifactUtil
.copyProperties(originalProperties
, myProperties
);
120 myEditor
= myProperties
.createEditor(myContext
);
124 public void applyProperties() {
126 final ModifiableArtifact artifact
= myContext
.getOrCreateModifiableArtifactModel().getOrCreateModifiableArtifact(myOriginalArtifact
);
127 artifact
.setProperties(myProvider
, myProperties
);
130 public boolean isModified() {
131 return myEditor
.isModified();