mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
StructureView ModelListener added
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2004 JetBrains s.r.o. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* -Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* -Redistribution in binary form must reproduct the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of JetBrains or IntelliJ IDEA
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind. ALL
|
||||
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
|
||||
* BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
|
||||
* OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
|
||||
* IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
*/
|
||||
package com.intellij.ide.structureView;
|
||||
|
||||
public interface ModelListener {
|
||||
void onModelChanged();
|
||||
}
|
||||
@@ -40,6 +40,10 @@ public interface StructureViewModel extends TreeModel{
|
||||
|
||||
void removeEditorPositionListener(FileEditorPositionListener listener);
|
||||
|
||||
void addModelListener(ModelListener modelListener);
|
||||
|
||||
void removeModelListener(ModelListener modelListener);
|
||||
|
||||
StructureViewTreeElement getRoot();
|
||||
|
||||
void dispose();
|
||||
|
||||
@@ -124,5 +124,13 @@ public abstract class TextEditorBasedStructureViewModel implements StructureView
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addModelListener(ModelListener modelListener) {
|
||||
|
||||
}
|
||||
|
||||
public void removeModelListener(ModelListener modelListener) {
|
||||
|
||||
}
|
||||
|
||||
protected abstract Class[] getSuitableClasses();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.intellij.ide.structureView.newStructureView;
|
||||
|
||||
import com.intellij.ide.structureView.ModelListener;
|
||||
import com.intellij.ide.structureView.StructureViewModel;
|
||||
import com.intellij.ide.util.treeView.*;
|
||||
import com.intellij.ide.util.treeView.smartTree.SmartTreeStructure;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
@@ -13,14 +15,17 @@ import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
final class StructureTreeBuilder extends AbstractTreeBuilder {
|
||||
private final Project myProject;
|
||||
private final StructureViewModel myStructureModel;
|
||||
|
||||
private final MyCopyPasteListener myCopyPasteListener;
|
||||
private final PsiTreeChangeListener myPsiTreeChangeListener;
|
||||
private final ModelListener myModelListener;
|
||||
|
||||
public StructureTreeBuilder(Project project,
|
||||
JTree tree,
|
||||
DefaultTreeModel treeModel,
|
||||
AbstractTreeStructure treeStructure) {
|
||||
AbstractTreeStructure treeStructure,
|
||||
StructureViewModel structureModel) {
|
||||
super(
|
||||
tree,
|
||||
treeModel,
|
||||
@@ -28,18 +33,26 @@ final class StructureTreeBuilder extends AbstractTreeBuilder {
|
||||
);
|
||||
|
||||
myProject = project;
|
||||
myStructureModel = structureModel;
|
||||
|
||||
myPsiTreeChangeListener = new MyPsiTreeChangeListener();
|
||||
myModelListener = new ModelListener() {
|
||||
public void onModelChanged() {
|
||||
myUpdater.addSubtreeToUpdate(myRootNode);
|
||||
}
|
||||
};
|
||||
PsiManager.getInstance(myProject).addPsiTreeChangeListener(myPsiTreeChangeListener);
|
||||
|
||||
myCopyPasteListener = new MyCopyPasteListener();
|
||||
CopyPasteManager.getInstance().addContentChangedListener(myCopyPasteListener);
|
||||
initRootNode();
|
||||
myStructureModel.addModelListener(myModelListener);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
PsiManager.getInstance(myProject).removePsiTreeChangeListener(myPsiTreeChangeListener);
|
||||
CopyPasteManager.getInstance().removeContentChangedListener(myCopyPasteListener);
|
||||
myStructureModel.removeModelListener(myModelListener);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class StructureViewComponent extends JPanel implements TreeActionsOwner,
|
||||
SmartTreeStructure treeStructure = new SmartTreeStructure(project, myTreeModelWrapper);
|
||||
JTree tree = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode(treeStructure.getRootElement())));
|
||||
myAbstractTreeBuilder = new StructureTreeBuilder(project, tree,
|
||||
(DefaultTreeModel)tree.getModel(),treeStructure);
|
||||
(DefaultTreeModel)tree.getModel(),treeStructure,myTreeModelWrapper);
|
||||
myAbstractTreeBuilder.updateFromRoot();
|
||||
add(new JScrollPane(myAbstractTreeBuilder.getTree()), BorderLayout.CENTER);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.ide.util.treeView.smartTree.*;
|
||||
import com.intellij.ide.structureView.StructureViewModel;
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.ide.structureView.FileEditorPositionListener;
|
||||
import com.intellij.ide.structureView.ModelListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -67,4 +68,12 @@ public class TreeModelWrapper implements StructureViewModel {
|
||||
public void dispose() {
|
||||
myModel.dispose();
|
||||
}
|
||||
|
||||
public void addModelListener(ModelListener modelListener) {
|
||||
myModel.addModelListener(modelListener);
|
||||
}
|
||||
|
||||
public void removeModelListener(ModelListener modelListener) {
|
||||
myModel.removeModelListener(modelListener);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user