JavaAdapter (reverting optimization)

This commit is contained in:
Olesya Smirnova
2005-01-20 22:49:01 +03:00
parent 09e64dbea4
commit bcdcfe6991
7 changed files with 40 additions and 13 deletions
@@ -2,4 +2,11 @@ package com.intellij.ide.util.treeView.smartTree;
public interface Filter extends TreeAction{
boolean isVisible(TreeElement treeNode);
/**
*
* @return this means the filter will work when it is disabled (for example "Show fields" filter is filter hiding fields, but reverted)
*/
boolean isReverted();
}
@@ -17,10 +17,7 @@ import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.psi.PsiElement;
import org.jdom.Element;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.*;
/**
* @author Eugene Belyaev
@@ -100,7 +97,7 @@ public final class StructureViewFactoryImpl extends StructureViewFactory impleme
public void setActiveAction(final String name, final boolean state) {
List<String> activeActions = collectActiveActions();
Collection<String> activeActions = collectActiveActions();
if (state) {
activeActions.add(name);
@@ -111,20 +108,23 @@ public final class StructureViewFactoryImpl extends StructureViewFactory impleme
ACTIVE_ACTIONS = toString(activeActions);
}
private String toString(final List<String> activeActions) {
private String toString(final Collection<String> activeActions) {
final StringBuffer result = new StringBuffer();
for (Iterator<String> iterator = activeActions.iterator(); iterator.hasNext();) {
result.append(iterator.next());
if (iterator.hasNext()) {
result.append(",");
final String actionName = iterator.next();
if (actionName.trim().length() > 0) {
result.append(actionName);
if (iterator.hasNext()) {
result.append(",");
}
}
}
return result.toString();
}
private List<String> collectActiveActions() {
private Collection<String> collectActiveActions() {
final String[] strings = ACTIVE_ACTIONS.split(",");
return new ArrayList<String>(Arrays.asList(strings));
return new HashSet<String>(Arrays.asList(strings));
}
public boolean isActionActive(final String name) {
@@ -20,4 +20,8 @@ public class FieldsFilter implements Filter{
public String getName() {
return ID;
}
public boolean isReverted() {
return true;
}
}
@@ -27,4 +27,8 @@ public class InheritedMembersFilter implements Filter {
public String getName() {
return ID;
}
public boolean isReverted() {
return true;
}
}
@@ -25,4 +25,8 @@ public class PublicElementsFilter implements Filter{
public String getName() {
return ID;
}
public boolean isReverted() {
return true;
}
}
@@ -25,10 +25,10 @@ public class TreeActionWrapper extends ToggleAction{
}
public boolean isSelected(AnActionEvent e) {
return myStructureView.isActionActive(myAction.getName());
return TreeModelWrapper.isActive(myAction, myStructureView);
}
public void setSelected(AnActionEvent e, boolean state) {
myStructureView.setActionActive(myAction.getName(), state);
myStructureView.setActionActive(myAction.getName(), TreeModelWrapper.shouldRevert(myAction) ? !state : state);
}
}
@@ -46,4 +46,12 @@ public class TreeModelWrapper implements StructureViewModel {
public Object getCurrentEditorElement() {
return myModel.getCurrentEditorElement();
}
public static boolean isActive(final TreeAction action, final TreeActionsOwner actionsOwner) {
return shouldRevert(action) ? !actionsOwner.isActionActive(action.getName()) : actionsOwner.isActionActive(action.getName());
}
public static boolean shouldRevert(final TreeAction action) {
return action instanceof Filter && ((Filter)action).isReverted();
}
}