standard modules added, tree state saved

This commit is contained in:
Dmitry Avdeev
2012-10-09 18:34:37 +04:00
parent bd8fce3609
commit fb7b58c843
8 changed files with 207 additions and 25 deletions
@@ -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<SelectTemplateSettings> {
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();
}
@@ -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<NodeDescriptor>() {
@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<SimpleNode> node = new Ref<SimpleNode>();
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;
@@ -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<MultiMap<String, URL>> myGroups = new NotNullLazyValue<MultiMap<String, URL>>() {
@NotNull
@Override
@@ -66,7 +68,7 @@ public class ArchivedTemplatesFactory implements ProjectTemplatesFactory {
try {
List<String> children = UrlUtil.getChildrenRelativePaths(url);
if (configURL == url && !children.isEmpty()) {
map.putValue("Custom", url);
map.putValue(CUSTOM_GROUP, url);
continue;
}
@@ -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<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
return ContainerUtil.map2Array(builders, ProjectTemplate.class, new Function<ModuleBuilder, ProjectTemplate>() {
@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;
}
};
}
});
}
}
@@ -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";
@@ -301,11 +301,6 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat
return myTree.select(configurable);
}
@NotNull
public List<Configurable> getPathToRoot(@NotNull Configurable configurable) {
return myTree.getPathToRoot(configurable);
}
private float readProportion(final float defaultValue, final String propertyName) {
float proportion = defaultValue;
try {
@@ -257,17 +257,6 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl
return path;
}
@Nullable
public Configurable getParentFor(final Configurable configurable) {
final List<Configurable> path = getPathToRoot(configurable);
if (path.size() > 1) {
return path.get(1);
}
else {
return null;
}
}
public SimpleNode findNodeFor(final Configurable toSelect) {
return myConfigurable2Node.get(toSelect);
}
@@ -299,6 +299,9 @@
<wizardMode implementation="com.intellij.ide.util.newProjectWizard.modes.ImportImlMode" id="ImportImlMode"/>
<projectTemplatesFactory implementation="com.intellij.platform.templates.ArchivedTemplatesFactory"/>
<projectTemplatesFactory implementation="com.intellij.platform.templates.EmptyModuleTemplatesFactory"/>
<applicationService serviceImplementation="com.intellij.ide.util.newProjectWizard.SelectTemplateSettings"/>
<gotoFileContributor implementation="com.intellij.ide.util.gotoByName.ProjectBaseDirNavigationContributor"/>