mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
code cleanup
This commit is contained in:
+1
-1
@@ -35,7 +35,7 @@ public final class AntBuildFilePropertiesAction extends AnAction {
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
myAntExplorer.setBuildFileProperties(e.getDataContext());
|
||||
myAntExplorer.setBuildFileProperties();
|
||||
}
|
||||
|
||||
public void update(AnActionEvent event) {
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.intellij.lang.ant.config.impl.configuration.BuildFilePropertiesPanel;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
@@ -76,25 +75,22 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AntExplorer extends SimpleToolWindowPanel implements DataProvider, Disposable {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.lang.ant.config.explorer.AntExplorer");
|
||||
|
||||
private Project myProject;
|
||||
private AntExplorerTreeBuilder myBuilder;
|
||||
private Tree myTree;
|
||||
private KeymapListener myKeymapListener;
|
||||
private final AntBuildFilePropertiesAction myAntBuildFilePropertiesAction;
|
||||
private final MergingUpdateQueue myQueue;
|
||||
private AntConfiguration myConfig;
|
||||
|
||||
|
||||
private final TreeExpander myTreeExpander = new TreeExpander() {
|
||||
public void expandAll() {
|
||||
myBuilder.expandAll();
|
||||
}
|
||||
|
||||
public boolean canExpand() {
|
||||
final Project project = myProject;
|
||||
return project != null && AntConfiguration.getInstance(project).getBuildFiles().length != 0;
|
||||
final AntConfiguration config = myConfig;
|
||||
return config != null && config.getBuildFiles().length != 0;
|
||||
}
|
||||
|
||||
public void collapseAll() {
|
||||
@@ -113,6 +109,7 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider,
|
||||
public AntExplorer(final Project project) {
|
||||
super(true, true);
|
||||
myProject = project;
|
||||
myConfig = AntConfiguration.getInstance(project);
|
||||
final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
|
||||
myTree = new Tree(model);
|
||||
myTree.setRootVisible(false);
|
||||
@@ -172,23 +169,29 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider,
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
myProject = null;
|
||||
if (myKeymapListener != null) {
|
||||
myKeymapListener.stopListen();
|
||||
final KeymapListener listener = myKeymapListener;
|
||||
if (listener != null) {
|
||||
myKeymapListener = null;
|
||||
listener.stopListen();
|
||||
}
|
||||
if (myBuilder != null) {
|
||||
Disposer.dispose(myBuilder);
|
||||
|
||||
final AntExplorerTreeBuilder builder = myBuilder;
|
||||
if (builder != null) {
|
||||
Disposer.dispose(builder);
|
||||
myBuilder = null;
|
||||
}
|
||||
myBuilder = null;
|
||||
if (myTree != null) {
|
||||
ToolTipManager.sharedInstance().unregisterComponent(myTree);
|
||||
final KeyStroke[] strokes = myTree.getRegisteredKeyStrokes();
|
||||
for (KeyStroke keyStroke : strokes) {
|
||||
myTree.unregisterKeyboardAction(keyStroke);
|
||||
|
||||
final Tree tree = myTree;
|
||||
if (tree != null) {
|
||||
ToolTipManager.sharedInstance().unregisterComponent(tree);
|
||||
for (KeyStroke keyStroke : tree.getRegisteredKeyStrokes()) {
|
||||
tree.unregisterKeyboardAction(keyStroke);
|
||||
}
|
||||
myTree = null;
|
||||
}
|
||||
|
||||
myProject = null;
|
||||
myConfig = null;
|
||||
}
|
||||
|
||||
private JPanel createToolbarPanel() {
|
||||
@@ -222,8 +225,11 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider,
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
final AntConfiguration antConfiguration = AntConfiguration.getInstance(myProject);
|
||||
final ArrayList<VirtualFile> ignoredFiles = new ArrayList<VirtualFile>();
|
||||
final AntConfiguration antConfiguration = myConfig;
|
||||
if (antConfiguration == null) {
|
||||
return;
|
||||
}
|
||||
final List<VirtualFile> ignoredFiles = new ArrayList<VirtualFile>();
|
||||
for (VirtualFile file : files) {
|
||||
try {
|
||||
antConfiguration.addBuildFile(file);
|
||||
@@ -264,14 +270,13 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider,
|
||||
if (result != 0) {
|
||||
return;
|
||||
}
|
||||
AntConfiguration.getInstance(myProject).removeBuildFile(buildFile);
|
||||
myConfig.removeBuildFile(buildFile);
|
||||
}
|
||||
|
||||
public void setBuildFileProperties(DataContext dataContext) {
|
||||
final AntBuildFile buildFile = getCurrentBuildFile();
|
||||
if (BuildFilePropertiesPanel.editBuildFile(getCurrentBuildFile())) {
|
||||
final AntConfiguration antConfiguration = AntConfiguration.getInstance(myProject);
|
||||
antConfiguration.updateBuildFile(buildFile);
|
||||
public void setBuildFileProperties() {
|
||||
final AntBuildFileBase buildFile = getCurrentBuildFile();
|
||||
if (buildFile != null && BuildFilePropertiesPanel.editBuildFile(buildFile)) {
|
||||
myConfig.updateBuildFile(buildFile);
|
||||
myBuilder.refresh();
|
||||
myTree.repaint();
|
||||
}
|
||||
@@ -282,9 +287,11 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider,
|
||||
return;
|
||||
}
|
||||
final AntBuildFileBase buildFile = getCurrentBuildFile();
|
||||
final TreePath[] paths = myTree.getSelectionPaths();
|
||||
final String[] targets = getTargetNamesFromPaths(paths);
|
||||
ExecutionHandler.runBuild(buildFile, targets, null, dataContext, Collections.<BuildFileProperty>emptyList(), AntBuildListener.NULL);
|
||||
if (buildFile != null) {
|
||||
final TreePath[] paths = myTree.getSelectionPaths();
|
||||
final String[] targets = getTargetNamesFromPaths(paths);
|
||||
ExecutionHandler.runBuild(buildFile, targets, null, dataContext, Collections.<BuildFileProperty>emptyList(), AntBuildListener.NULL);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canRunSelection() {
|
||||
|
||||
@@ -31,23 +31,31 @@ import javax.swing.*;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class AntExplorerTreeBuilder extends AbstractTreeBuilder {
|
||||
|
||||
private static final TreePath[] EMPTY_TREE_PATH = new TreePath[0];
|
||||
private final AntConfigurationListener myAntBuildListener;
|
||||
private final Project myProject;
|
||||
|
||||
private AntConfiguration myConfig;
|
||||
|
||||
public AntExplorerTreeBuilder(Project project, JTree tree, DefaultTreeModel treeModel) {
|
||||
super(tree, treeModel, new AntExplorerTreeStructure(project), IndexComparator.INSTANCE);
|
||||
myProject = project;
|
||||
myAntBuildListener = new ConfigurationListener();
|
||||
AntConfiguration.getInstance(myProject).addAntConfigurationListener(myAntBuildListener);
|
||||
myConfig = AntConfiguration.getInstance(myProject);
|
||||
myConfig.addAntConfigurationListener(myAntBuildListener);
|
||||
initRootNode();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
final AntConfiguration config = myConfig;
|
||||
if (config != null) {
|
||||
config.removeAntConfigurationListener(myAntBuildListener);
|
||||
myConfig = null;
|
||||
}
|
||||
super.dispose();
|
||||
AntConfiguration.getInstance(myProject).removeAntConfigurationListener(myAntBuildListener);
|
||||
}
|
||||
|
||||
protected boolean isAlwaysShowPlus(NodeDescriptor nodeDescriptor) {
|
||||
@@ -59,33 +67,22 @@ final class AntExplorerTreeBuilder extends AbstractTreeBuilder {
|
||||
}
|
||||
|
||||
public void setTargetsFiltered(boolean value) {
|
||||
ArrayList pathsToExpand = new ArrayList();
|
||||
ArrayList selectionPaths = new ArrayList();
|
||||
TreeBuilderUtil.storePaths(this, getRootNode(), pathsToExpand, selectionPaths, true);
|
||||
((AntExplorerTreeStructure)getTreeStructure()).setFilteredTargets(value);
|
||||
ApplicationManager.getApplication().runReadAction(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
updateFromRoot();
|
||||
}
|
||||
}
|
||||
);
|
||||
getTree().setSelectionPaths(new TreePath[0]);
|
||||
TreeBuilderUtil.restorePaths(this, pathsToExpand, selectionPaths, true);
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
ArrayList pathsToExpand = new ArrayList();
|
||||
ArrayList selectionPaths = new ArrayList();
|
||||
public final void refresh() {
|
||||
final List<Object> pathsToExpand = new ArrayList<Object>();
|
||||
final List<Object> selectionPaths = new ArrayList<Object>();
|
||||
TreeBuilderUtil.storePaths(this, getRootNode(), pathsToExpand, selectionPaths, true);
|
||||
ApplicationManager.getApplication().runReadAction(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
updateFromRoot();
|
||||
queueUpdate();
|
||||
}
|
||||
}
|
||||
);
|
||||
getTree().setSelectionPaths(new TreePath[0]);
|
||||
getTree().setSelectionPaths(EMPTY_TREE_PATH);
|
||||
TreeBuilderUtil.restorePaths(this, pathsToExpand, selectionPaths, true);
|
||||
}
|
||||
|
||||
@@ -95,41 +92,41 @@ final class AntExplorerTreeBuilder extends AbstractTreeBuilder {
|
||||
|
||||
private final class ConfigurationListener implements AntConfigurationListener {
|
||||
public void configurationLoaded() {
|
||||
getUpdater().addSubtreeToUpdate(getRootNode());
|
||||
queueUpdate();
|
||||
}
|
||||
|
||||
public void buildFileAdded(AntBuildFile buildFile) {
|
||||
getUpdater().addSubtreeToUpdate(getRootNode());
|
||||
queueUpdate();
|
||||
}
|
||||
|
||||
public void buildFileChanged(AntBuildFile buildFile) {
|
||||
getUpdater().addSubtreeToUpdateByElement(buildFile);
|
||||
queueUpdateFrom(buildFile, false);
|
||||
}
|
||||
|
||||
public void buildFileRemoved(AntBuildFile buildFile) {
|
||||
getUpdater().addSubtreeToUpdate(getRootNode());
|
||||
queueUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void expandAll() {
|
||||
ArrayList pathsToExpand = new ArrayList();
|
||||
ArrayList selectionPaths = new ArrayList();
|
||||
final List<Object> pathsToExpand = new ArrayList<Object>();
|
||||
final List<Object> selectionPaths = new ArrayList<Object>();
|
||||
TreeBuilderUtil.storePaths(this, getRootNode(), pathsToExpand, selectionPaths, true);
|
||||
int row = 0;
|
||||
while (row < getTree().getRowCount()) {
|
||||
getTree().expandRow(row);
|
||||
row++;
|
||||
}
|
||||
getTree().setSelectionPaths(new TreePath[0]);
|
||||
getTree().setSelectionPaths(EMPTY_TREE_PATH);
|
||||
TreeBuilderUtil.restorePaths(this, pathsToExpand, selectionPaths, true);
|
||||
}
|
||||
|
||||
void collapseAll() {
|
||||
ArrayList pathsToExpand = new ArrayList();
|
||||
ArrayList selectionPaths = new ArrayList();
|
||||
final List<Object> pathsToExpand = new ArrayList<Object>();
|
||||
final List<Object> selectionPaths = new ArrayList<Object>();
|
||||
TreeBuilderUtil.storePaths(this, getRootNode(), pathsToExpand, selectionPaths, true);
|
||||
TreeUtil.collapseAll(getTree(), 1);
|
||||
getTree().setSelectionPaths(new TreePath[0]);
|
||||
getTree().setSelectionPaths(EMPTY_TREE_PATH);
|
||||
pathsToExpand.clear();
|
||||
TreeBuilderUtil.restorePaths(this, pathsToExpand, selectionPaths, true);
|
||||
}
|
||||
|
||||
+12
-7
@@ -55,15 +55,19 @@ final class AntExplorerTreeStructure extends AbstractTreeStructure {
|
||||
if (element == myRoot) {
|
||||
return new RootNodeDescriptor(myProject, parentDescriptor);
|
||||
}
|
||||
else if (element instanceof String) {
|
||||
|
||||
if (element instanceof String) {
|
||||
return new TextInfoNodeDescriptor(myProject, parentDescriptor, (String)element);
|
||||
}
|
||||
else if (element instanceof AntBuildFile) {
|
||||
|
||||
if (element instanceof AntBuildFileBase) {
|
||||
return new AntBuildFileNodeDescriptor(myProject, parentDescriptor, (AntBuildFileBase)element);
|
||||
}
|
||||
else if (element instanceof AntBuildTarget) {
|
||||
|
||||
if (element instanceof AntBuildTargetBase) {
|
||||
return new AntTargetNodeDescriptor(myProject, parentDescriptor, (AntBuildTargetBase)element);
|
||||
}
|
||||
|
||||
LOG.error("Unknown element for this tree structure " + element);
|
||||
return null;
|
||||
}
|
||||
@@ -90,7 +94,7 @@ final class AntExplorerTreeStructure extends AbstractTreeStructure {
|
||||
Collections.sort(metaTargets, ourTargetComparator);
|
||||
targets.addAll(metaTargets);
|
||||
|
||||
return targets.toArray(new AntBuildTargetBase[targets.size()]);
|
||||
return targets.toArray(new AntBuildTarget[targets.size()]);
|
||||
}
|
||||
|
||||
if (element instanceof AntBuildTarget) {
|
||||
@@ -106,12 +110,13 @@ final class AntExplorerTreeStructure extends AbstractTreeStructure {
|
||||
if (element instanceof MetaTarget) {
|
||||
return ((MetaTarget)element).getBuildFile();
|
||||
}
|
||||
AntBuildTargetBase buildTarget = (AntBuildTargetBase)element;
|
||||
return buildTarget.getModel().getBuildFile();
|
||||
return ((AntBuildTarget)element).getModel().getBuildFile();
|
||||
}
|
||||
else if (element instanceof AntBuildFile) {
|
||||
|
||||
if (element instanceof AntBuildFile) {
|
||||
return myRoot;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user