diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateSettings.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateSettings.java new file mode 100644 index 000000000000..4bc065fc4f81 --- /dev/null +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateSettings.java @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2012 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.ide.util.newProjectWizard; + +import com.intellij.ide.util.treeView.TreeState; +import com.intellij.openapi.components.*; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.WriteExternalException; +import com.intellij.util.xmlb.annotations.Tag; +import com.intellij.util.xmlb.annotations.Transient; +import org.jdom.Element; +import org.jetbrains.annotations.Nullable; + +/** + * @author Dmitry Avdeev + * Date: 10/9/12 + */ +@State(name = "SelectProjectTemplateSettings", storages = {@Storage( file = StoragePathMacros.APP_CONFIG + "/other.xml")}) +public class SelectTemplateSettings implements PersistentStateComponent { + + static SelectTemplateSettings getInstance() { + return ServiceManager.getService(SelectTemplateSettings.class); + } + + @Transient + public TreeState getTreeState() { + return myTreeState; + } + + @Transient + public void setTreeState(TreeState state) { + myTreeState = state; + } + + @Nullable + @Override + public SelectTemplateSettings getState() { + try { + myTreeState.writeExternal(treeState); + } + catch (WriteExternalException ignore) { + } + return this; + } + + @Override + public void loadState(SelectTemplateSettings state) { + try { + myTreeState.readExternal(state.treeState); + } + catch (InvalidDataException ignore) { + } + } + + @Tag("treeState") + public Element treeState = new Element("treeState"); + + private TreeState myTreeState = new TreeState(); +} diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java index f92ce0a7877f..a4315b73687a 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java @@ -18,12 +18,16 @@ package com.intellij.ide.util.newProjectWizard; import com.intellij.ide.util.projectWizard.ModuleWizardStep; import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.ide.util.treeView.AlphaComparator; +import com.intellij.ide.util.treeView.NodeDescriptor; +import com.intellij.ide.util.treeView.TreeState; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.platform.ProjectTemplate; import com.intellij.platform.ProjectTemplatesFactory; +import com.intellij.platform.templates.ArchivedTemplatesFactory; +import com.intellij.platform.templates.EmptyModuleTemplatesFactory; import com.intellij.psi.codeStyle.MinusculeMatcher; import com.intellij.psi.codeStyle.NameUtil; import com.intellij.ui.ColoredTreeCellRenderer; @@ -47,10 +51,8 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import java.awt.*; -import java.util.ArrayList; -import java.util.Collection; +import java.util.*; import java.util.List; -import java.util.Map; /** * @author Dmitry Avdeev @@ -102,7 +104,23 @@ public class SelectTemplateStep extends ModuleWizardStep { return matches(template); } }; - myBuilder = new FilteringTreeBuilder(myTemplatesTree, myFilter, structure, AlphaComparator.INSTANCE); + myBuilder = new FilteringTreeBuilder(myTemplatesTree, myFilter, structure, new Comparator() { + @Override + public int compare(NodeDescriptor o1, NodeDescriptor o2) { + if (o1 instanceof FilteringTreeStructure.FilteringNode) { + if (((FilteringTreeStructure.FilteringNode)o1).getDelegate() instanceof GroupNode) { + String name = ((GroupNode)((FilteringTreeStructure.FilteringNode)o1).getDelegate()).getName(); + if (name.equals(EmptyModuleTemplatesFactory.GROUP_NAME)) { +// return 1; + } + else if (name.equals(ArchivedTemplatesFactory.CUSTOM_GROUP)) { +// return -1; + } + } + } + return AlphaComparator.INSTANCE.compare(o1, o2); + } + }); myTemplatesTree.setRootVisible(false); myTemplatesTree.setShowsRootHandles(false); @@ -137,6 +155,7 @@ public class SelectTemplateStep extends ModuleWizardStep { } ProjectTemplate template = getSelectedTemplate(); if (template != null) { +// PropertiesComponent JComponent settingsPanel = template.getSettingsPanel(); if (settingsPanel != null) { mySettingsPanel.add(settingsPanel, BorderLayout.NORTH); @@ -165,6 +184,11 @@ public class SelectTemplateStep extends ModuleWizardStep { } }); // doFilter(); + + TreeState state = SelectTemplateSettings.getInstance().getTreeState(); + if (state != null) { + state.applyTo(myTemplatesTree, (DefaultMutableTreeNode)myTemplatesTree.getModel().getRoot()); + } } @Override @@ -174,7 +198,7 @@ public class SelectTemplateStep extends ModuleWizardStep { private void doFilter() { buildMatcher(); - SimpleNode selectedNode = getSelectedNode(); + SimpleNode selectedNode = myTemplatesTree.getSelectedNode(); final Ref node = new Ref(); if (!(selectedNode instanceof TemplateNode) || !matches(selectedNode)) { myTemplatesTree.accept(myBuilder, new SimpleNodeVisitor() { @@ -233,7 +257,8 @@ public class SelectTemplateStep extends ModuleWizardStep { private SimpleNode getSimpleNode(Object component) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)component; Object userObject = node.getUserObject(); - if (!(userObject instanceof FilteringTreeStructure.FilteringNode)) return null; + if (!(userObject instanceof FilteringTreeStructure.FilteringNode)) //noinspection ConstantConditions + return null; FilteringTreeStructure.FilteringNode object = (FilteringTreeStructure.FilteringNode)userObject; return (SimpleNode)object.getDelegate(); } @@ -252,6 +277,19 @@ public class SelectTemplateStep extends ModuleWizardStep { public void updateDataModel() { } + @Override + public void onStepLeaving() { + TreePath path = myTemplatesTree.getSelectionPath(); + TreeState state; + if (path == null) { + state = TreeState.createOn(myTemplatesTree); + } + else { + state = TreeState.createOn(myTemplatesTree, (DefaultMutableTreeNode)path.getLastPathComponent()); + } + SelectTemplateSettings.getInstance().setTreeState(state); + } + @Override public void disposeUIResources() { Disposer.dispose(myBuilder); @@ -278,7 +316,6 @@ public class SelectTemplateStep extends ModuleWizardStep { return children.toArray(new SimpleNode[children.size()]); } - @Override public String getName() { return myGroup; diff --git a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java index cf625871917d..861717875b44 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java @@ -41,7 +41,9 @@ import java.util.*; */ public class ArchivedTemplatesFactory implements ProjectTemplatesFactory { + public static final String CUSTOM_GROUP = "Custom"; private static final String ZIP = ".zip"; + private final NotNullLazyValue> myGroups = new NotNullLazyValue>() { @NotNull @Override @@ -66,7 +68,7 @@ public class ArchivedTemplatesFactory implements ProjectTemplatesFactory { try { List children = UrlUtil.getChildrenRelativePaths(url); if (configURL == url && !children.isEmpty()) { - map.putValue("Custom", url); + map.putValue(CUSTOM_GROUP, url); continue; } diff --git a/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java new file mode 100644 index 000000000000..2a5080e415aa --- /dev/null +++ b/java/idea-ui/src/com/intellij/platform/templates/EmptyModuleTemplatesFactory.java @@ -0,0 +1,80 @@ +/* + * Copyright 2000-2012 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.platform.templates; + +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.ide.util.projectWizard.ProjectBuilder; +import com.intellij.ide.util.projectWizard.WizardContext; +import com.intellij.platform.ProjectTemplate; +import com.intellij.platform.ProjectTemplatesFactory; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.List; + +/** + * @author Dmitry Avdeev + * Date: 10/9/12 + */ +public class EmptyModuleTemplatesFactory implements ProjectTemplatesFactory { + + public static final String GROUP_NAME = "Standard"; + + @NotNull + @Override + public String[] getGroups() { + return new String[] {GROUP_NAME}; + } + + @NotNull + @Override + public ProjectTemplate[] createTemplates(String group, WizardContext context) { + List builders = ModuleBuilder.getAllBuilders(); + return ContainerUtil.map2Array(builders, ProjectTemplate.class, new Function() { + @Override + public ProjectTemplate fun(final ModuleBuilder builder) { + return new ProjectTemplate() { + @NotNull + @Override + public String getName() { + return builder.getPresentableName(); + } + + @Nullable + @Override + public String getDescription() { + return builder.getDescription(); + } + + @Nullable + @Override + public JComponent getSettingsPanel() { + return null; + } + + @NotNull + @Override + public ProjectBuilder createModuleBuilder() { + return builder; + } + }; + } + }); + } +} diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java index 0e477dddab7b..bf3888418c6e 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java @@ -34,7 +34,11 @@ import java.util.ArrayList; import java.util.List; /** - * Main entry point is {@link #createOn(javax.swing.JTree)} + * @see #createOn(javax.swing.JTree) + * @see #createOn(javax.swing.JTree, javax.swing.tree.DefaultMutableTreeNode) + * + * @see #applyTo(javax.swing.JTree) + * @see #applyTo(javax.swing.JTree, javax.swing.tree.DefaultMutableTreeNode) */ public class TreeState implements JDOMExternalizable { @NonNls private static final String PATH = "PATH"; diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java index b84476be5a57..cb6a861c130e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java @@ -301,11 +301,6 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat return myTree.select(configurable); } - @NotNull - public List getPathToRoot(@NotNull Configurable configurable) { - return myTree.getPathToRoot(configurable); - } - private float readProportion(final float defaultValue, final String propertyName) { float proportion = defaultValue; try { diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java index be3330db1bf5..3c504642fc68 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java @@ -257,17 +257,6 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl return path; } - @Nullable - public Configurable getParentFor(final Configurable configurable) { - final List path = getPathToRoot(configurable); - if (path.size() > 1) { - return path.get(1); - } - else { - return null; - } - } - public SimpleNode findNodeFor(final Configurable toSelect) { return myConfigurable2Node.get(toSelect); } diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index b7303944ba3b..a3284049db16 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -299,6 +299,9 @@ + + +