mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
frameworks tree refactored
This commit is contained in:
@@ -10,21 +10,19 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class FrameworkGroup<V extends FrameworkGroupVersion> {
|
||||
public abstract class FrameworkGroup<V extends FrameworkGroupVersion> implements FrameworkOrGroup {
|
||||
private final String myId;
|
||||
|
||||
public FrameworkGroup(String id) {
|
||||
myId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final String getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract String getPresentableName();
|
||||
|
||||
@NotNull
|
||||
public abstract Icon getIcon();
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.framework;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 09.10.13
|
||||
*/
|
||||
public interface FrameworkOrGroup {
|
||||
@NotNull
|
||||
String getId();
|
||||
|
||||
String getPresentableName();
|
||||
|
||||
Icon getIcon();
|
||||
}
|
||||
-4
@@ -33,10 +33,6 @@ public abstract class FrameworkSupportInModuleConfigurable implements Disposable
|
||||
@Nullable
|
||||
public abstract JComponent createComponent();
|
||||
|
||||
public JComponent createComponent(boolean inline) {
|
||||
return createComponent();
|
||||
}
|
||||
|
||||
public abstract void addSupport(@NotNull Module module, @NotNull ModifiableRootModel rootModel,
|
||||
@NotNull ModifiableModelsProvider modifiableModelsProvider);
|
||||
|
||||
|
||||
+15
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.framework.addSupport;
|
||||
|
||||
import com.intellij.framework.FrameworkOrGroup;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkRole;
|
||||
import com.intellij.framework.FrameworkTypeEx;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
|
||||
@@ -24,13 +25,15 @@ import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class FrameworkSupportInModuleProvider {
|
||||
public abstract class FrameworkSupportInModuleProvider implements FrameworkOrGroup {
|
||||
|
||||
@NotNull
|
||||
public abstract FrameworkTypeEx getFrameworkType();
|
||||
|
||||
@@ -72,6 +75,17 @@ public abstract class FrameworkSupportInModuleProvider {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getId() {
|
||||
return getFrameworkType().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return getFrameworkType().getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPresentableName();
|
||||
|
||||
+8
-9
@@ -81,7 +81,7 @@ public class AddSupportForFrameworksPanel implements Disposable {
|
||||
|
||||
myLabel.setVisible(!vertical);
|
||||
Splitter splitter = vertical ? new Splitter(true, 0.6f) : new Splitter(false, 0.3f, 0.1f, 0.7f);
|
||||
myFrameworksTree = new FrameworksTree() {
|
||||
myFrameworksTree = new FrameworksTree(model) {
|
||||
@Override
|
||||
protected void onNodeStateChanged(CheckedTreeNode node) {
|
||||
if (!(node instanceof FrameworkSupportNode)) return;
|
||||
@@ -156,12 +156,12 @@ public class AddSupportForFrameworksPanel implements Disposable {
|
||||
if (node instanceof FrameworkSupportNode) {
|
||||
FrameworkSupportNode frameworkSupportNode = (FrameworkSupportNode)node;
|
||||
initializeOptionsPanel(frameworkSupportNode);
|
||||
showCard(frameworkSupportNode.getProvider().getFrameworkType().getId());
|
||||
showCard(frameworkSupportNode.getId());
|
||||
UIUtil.setEnabled(myOptionsPanel, frameworkSupportNode.isChecked(), true);
|
||||
frameworkSupportNode.getConfigurable().onFrameworkSelectionChanged(node.isChecked());
|
||||
}
|
||||
else if (node instanceof FrameworkGroupNode) {
|
||||
FrameworkGroup<?> group = ((FrameworkGroupNode)node).getGroup();
|
||||
FrameworkGroup<?> group = ((FrameworkGroupNode)node).getUserObject();
|
||||
initializeGroupPanel(group);
|
||||
showCard(group.getId());
|
||||
UIUtil.setEnabled(myOptionsPanel, true, true);
|
||||
@@ -192,13 +192,12 @@ public class AddSupportForFrameworksPanel implements Disposable {
|
||||
initializeOptionsPanel((FrameworkSupportNode)parentNode);
|
||||
}
|
||||
else if (parentNode instanceof FrameworkGroupNode) {
|
||||
initializeGroupPanel(((FrameworkGroupNode)parentNode).getGroup());
|
||||
initializeGroupPanel(((FrameworkGroupNode)parentNode).getUserObject());
|
||||
}
|
||||
|
||||
FrameworkSupportOptionsComponent optionsComponent = new FrameworkSupportOptionsComponent(myModel, myLibrariesContainer, this,
|
||||
node.getProvider(), node.getConfigurable());
|
||||
final String id = node.getProvider().getFrameworkType().getId();
|
||||
myOptionsPanel.add(id, optionsComponent.getMainPanel());
|
||||
node.getUserObject(), node.getConfigurable());
|
||||
myOptionsPanel.add(node.getId(), optionsComponent.getMainPanel());
|
||||
myInitializedOptionsComponents.put(node, optionsComponent);
|
||||
}
|
||||
}
|
||||
@@ -333,7 +332,7 @@ public class AddSupportForFrameworksPanel implements Disposable {
|
||||
}
|
||||
}
|
||||
for (FrameworkSupportNode node : selectedFrameworks) {
|
||||
FrameworkSupportInModuleProvider provider = node.getProvider();
|
||||
FrameworkSupportInModuleProvider provider = node.getUserObject();
|
||||
if (provider instanceof OldFrameworkSupportProviderWrapper) {
|
||||
final FrameworkSupportProvider oldProvider = ((OldFrameworkSupportProviderWrapper)provider).getProvider();
|
||||
if (oldProvider instanceof FacetBasedFrameworkSupportProvider && !addedLibraries.isEmpty()) {
|
||||
@@ -350,7 +349,7 @@ public class AddSupportForFrameworksPanel implements Disposable {
|
||||
final Comparator<FrameworkSupportInModuleProvider> comparator = FrameworkSupportUtil.getFrameworkSupportProvidersComparator(myProviders);
|
||||
Collections.sort(nodes, new Comparator<FrameworkSupportNode>() {
|
||||
public int compare(final FrameworkSupportNode o1, final FrameworkSupportNode o2) {
|
||||
return comparator.compare(o1.getProvider(), o2.getProvider());
|
||||
return comparator.compare(o1.getUserObject(), o2.getUserObject());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,38 +3,12 @@ package com.intellij.ide.util.newProjectWizard;
|
||||
import com.intellij.framework.FrameworkGroup;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class FrameworkGroupNode extends FrameworkSupportNodeBase {
|
||||
private final FrameworkGroup<?> myGroup;
|
||||
public class FrameworkGroupNode extends FrameworkSupportNodeBase<FrameworkGroup> {
|
||||
|
||||
public FrameworkGroupNode(@NotNull FrameworkGroup<?> group, FrameworkSupportNodeBase parent) {
|
||||
super(group, parent);
|
||||
myGroup = group;
|
||||
}
|
||||
|
||||
public FrameworkGroup<?> getGroup() {
|
||||
return myGroup;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return myGroup.getPresentableName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return myGroup.getIcon();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getId() {
|
||||
return myGroup.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,11 @@ import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class FrameworkSupportNode extends FrameworkSupportNodeBase {
|
||||
private final FrameworkSupportInModuleProvider myProvider;
|
||||
public class FrameworkSupportNode extends FrameworkSupportNodeBase<FrameworkSupportInModuleProvider> {
|
||||
private FrameworkSupportInModuleConfigurable myConfigurable;
|
||||
private final FrameworkSupportModelBase myModel;
|
||||
private final Disposable myParentDisposable;
|
||||
@@ -37,37 +33,15 @@ public class FrameworkSupportNode extends FrameworkSupportNodeBase {
|
||||
Disposable parentDisposable) {
|
||||
super(provider, parentNode);
|
||||
myParentDisposable = parentDisposable;
|
||||
myProvider = provider;
|
||||
model.registerComponent(provider, this);
|
||||
myModel = model;
|
||||
}
|
||||
|
||||
public FrameworkSupportInModuleProvider getProvider() {
|
||||
return myProvider;
|
||||
}
|
||||
|
||||
public synchronized FrameworkSupportInModuleConfigurable getConfigurable() {
|
||||
if (myConfigurable == null) {
|
||||
myConfigurable = myProvider.createConfigurable(myModel);
|
||||
myConfigurable = getUserObject().createConfigurable(myModel);
|
||||
Disposer.register(myParentDisposable, myConfigurable);
|
||||
}
|
||||
return myConfigurable;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTitle() {
|
||||
return myProvider.getPresentableName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return myProvider.getFrameworkType().getIcon();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getId() {
|
||||
return myProvider.getFrameworkType().getId();
|
||||
}
|
||||
}
|
||||
|
||||
+17
-5
@@ -1,5 +1,6 @@
|
||||
package com.intellij.ide.util.newProjectWizard;
|
||||
|
||||
import com.intellij.framework.FrameworkOrGroup;
|
||||
import com.intellij.ui.CheckedTreeNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -12,10 +13,10 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class FrameworkSupportNodeBase extends CheckedTreeNode {
|
||||
public abstract class FrameworkSupportNodeBase<T extends FrameworkOrGroup> extends CheckedTreeNode {
|
||||
private final FrameworkSupportNodeBase myParentNode;
|
||||
|
||||
public FrameworkSupportNodeBase(Object userObject, final FrameworkSupportNodeBase parentNode) {
|
||||
public FrameworkSupportNodeBase(T userObject, final FrameworkSupportNodeBase parentNode) {
|
||||
super(userObject);
|
||||
setChecked(false);
|
||||
myParentNode = parentNode;
|
||||
@@ -24,6 +25,11 @@ public abstract class FrameworkSupportNodeBase extends CheckedTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getUserObject() {
|
||||
return (T)super.getUserObject();
|
||||
}
|
||||
|
||||
public static void sortByName(@Nullable List<FrameworkSupportNodeBase> nodes) {
|
||||
if (nodes == null) return;
|
||||
|
||||
@@ -42,13 +48,19 @@ public abstract class FrameworkSupportNodeBase extends CheckedTreeNode {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String getTitle();
|
||||
protected final String getTitle() {
|
||||
return getUserObject().getPresentableName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract Icon getIcon();
|
||||
public final Icon getIcon() {
|
||||
return getUserObject().getIcon();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract String getId();
|
||||
public final String getId() {
|
||||
return getUserObject().getId();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<FrameworkSupportNodeBase> getChildren() {
|
||||
|
||||
+2
-2
@@ -128,8 +128,8 @@ public class FrameworkSupportOptionsComponent {
|
||||
return new FrameworkLibraryVersionFilter() {
|
||||
@Override
|
||||
public boolean isAccepted(@NotNull FrameworkLibraryVersion version) {
|
||||
return myConfigurable.getLibraryVersionFilter().isAccepted(version) && ((FrameworkLibraryVersionImpl)version).getAvailabilityCondition().isAvailableFor(
|
||||
myModel);
|
||||
return myConfigurable.getLibraryVersionFilter().isAccepted(version) &&
|
||||
((FrameworkLibraryVersionImpl)version).getAvailabilityCondition().isAvailableFor(myModel);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.ide.util.newProjectWizard;
|
||||
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase;
|
||||
import com.intellij.ui.CheckboxTree;
|
||||
import com.intellij.ui.CheckedTreeNode;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
@@ -27,7 +29,6 @@ import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -36,20 +37,19 @@ import java.util.List;
|
||||
public class FrameworksTree extends CheckboxTree {
|
||||
private boolean myProcessingMouseEventOnCheckbox;
|
||||
|
||||
public FrameworksTree() {
|
||||
this(Collections.<FrameworkSupportNodeBase>emptyList());
|
||||
}
|
||||
|
||||
public FrameworksTree(List<FrameworkSupportNodeBase> roots) {
|
||||
super(new FrameworksTreeRenderer(), new FrameworksRootNode(roots), new CheckPolicy(false, true, true, false));
|
||||
public FrameworksTree(FrameworkSupportModelBase model) {
|
||||
super(new FrameworksTreeRenderer(model), new CheckedTreeNode(), new CheckPolicy(false, true, true, false));
|
||||
setRootVisible(false);
|
||||
setShowsRootHandles(false);
|
||||
putClientProperty("JTree.lineStyle", "None");
|
||||
TreeUtil.expandAll(this);
|
||||
}
|
||||
|
||||
public void setRoots(List<FrameworkSupportNodeBase> roots) {
|
||||
setModel(new DefaultTreeModel(new FrameworksRootNode(roots)));
|
||||
CheckedTreeNode root = new CheckedTreeNode(null);
|
||||
for (FrameworkSupportNodeBase base : roots) {
|
||||
root.add(base);
|
||||
}
|
||||
setModel(new DefaultTreeModel(root));
|
||||
TreeUtil.expandAll(this);
|
||||
}
|
||||
|
||||
@@ -97,8 +97,11 @@ public class FrameworksTree extends CheckboxTree {
|
||||
}
|
||||
|
||||
private static class FrameworksTreeRenderer extends CheckboxTreeCellRenderer {
|
||||
private FrameworksTreeRenderer() {
|
||||
private final FrameworkSupportModelBase myModel;
|
||||
|
||||
private FrameworksTreeRenderer(FrameworkSupportModelBase model) {
|
||||
super(true, false);
|
||||
myModel = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,15 +112,11 @@ public class FrameworksTree extends CheckboxTree {
|
||||
getTextRenderer().append(node.getTitle(), attributes);
|
||||
getTextRenderer().setIcon(node.getIcon());
|
||||
getCheckbox().setVisible(value instanceof FrameworkSupportNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class FrameworksRootNode extends CheckedTreeNode {
|
||||
public FrameworksRootNode(List<FrameworkSupportNodeBase> roots) {
|
||||
super(null);
|
||||
for (FrameworkSupportNodeBase node : roots) {
|
||||
add(node);
|
||||
Object object = node.getUserObject();
|
||||
if (object instanceof FrameworkSupportInModuleProvider) {
|
||||
// myModel.getSelectedVersion()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -184,7 +184,7 @@ public abstract class FrameworkSupportModelBase extends UserDataHolderBase imple
|
||||
|
||||
public void onFrameworkSelectionChanged(FrameworkSupportNode node) {
|
||||
final FrameworkSupportModelListener multicaster = myDispatcher.getMulticaster();
|
||||
final FrameworkSupportInModuleProvider provider = node.getProvider();
|
||||
final FrameworkSupportInModuleProvider provider = node.getUserObject();
|
||||
//todo[nik]
|
||||
if (provider instanceof OldFrameworkSupportProviderWrapper) {
|
||||
final FrameworkSupportProvider oldProvider = ((OldFrameworkSupportProviderWrapper) provider).getProvider();
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public abstract class FrameworkSupportProviderTestCase extends IdeaTestCase {
|
||||
final IdeaModifiableModelsProvider modelsProvider = new IdeaModifiableModelsProvider();
|
||||
for (FrameworkSupportNode node : myNodes.values()) {
|
||||
if (node.isChecked()) {
|
||||
final FrameworkSupportInModuleConfigurable configurable = getOrCreateConfigurable(node.getProvider());
|
||||
final FrameworkSupportInModuleConfigurable configurable = getOrCreateConfigurable(node.getUserObject());
|
||||
configurable.addSupport(myModule, model, modelsProvider);
|
||||
if (configurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) {
|
||||
selectedConfigurables.add(((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper)configurable).getConfigurable());
|
||||
|
||||
@@ -26,6 +26,10 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
public class CheckedTreeNode extends DefaultMutableTreeNode {
|
||||
protected boolean isChecked = true;
|
||||
private boolean isEnabled = true;
|
||||
|
||||
public CheckedTreeNode() {
|
||||
}
|
||||
|
||||
public CheckedTreeNode(Object userObject) {
|
||||
super(userObject);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user