Skip to content

Commit

Permalink
[Model Tree] Persist state of hidden top-level folders and add a "Sho…
Browse files Browse the repository at this point in the history
…w All" menu item

- We set the TreeViewer model input later in doCreatePartControl so that any viewer filters are applied first. Adding a viewer filter calls refresh() on the tree and so is expensive.
  • Loading branch information
Phillipus committed Jan 19, 2025
1 parent a493e52 commit c29f922
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Messages extends NLS {

public static String TreeModelView_5;

public static String TreeModelView_6;

public static String TreeModelViewerDragDropHandler_0;
static {
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.beans.PropertyChangeEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -138,6 +139,9 @@ public TreeModelView() {

@Override
public void doCreatePartControl(Composite parent) {
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);

GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
Expand All @@ -147,13 +151,10 @@ public void doCreatePartControl(Composite parent) {
fTreeViewer = new TreeModelViewer(parent, SWT.NULL);
fTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

fTreeViewer.setInput(IEditorModelManager.INSTANCE);

// Drill down
fDrillDownAdapter = new DrillDownAdapter(fTreeViewer);

/*
* Listen to Double-click and press Return Action
*/
// Listen to Double-click and press Return Action
fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
Expand Down Expand Up @@ -188,14 +189,14 @@ public void selectionChanged(SelectionChangedEvent event) {
// Drag support
new TreeModelViewerDragDropHandler(fTreeViewer);

// Expand tree elements
TreeStateHelper.INSTANCE.restoreExpandedTreeElements(fTreeViewer);
// Set model input now
fTreeViewer.setInput(IEditorModelManager.INSTANCE);

// Expand tree elements after model input
TreeStateHelper.INSTANCE.restoreExpandedTreeElements(fTreeViewer);

// This will update previous Undo/Redo text if Tree was closed before
updateActions();

// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}

@Override
Expand Down Expand Up @@ -575,18 +576,25 @@ class FolderFilter extends ViewerFilter {

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return element instanceof IFolder ? ((IFolder)element).getType() != type : true;
return element instanceof IFolder folder ? folder.getType() != type : true;
}
}

// Filter folder action
class FolderFilterAction extends Action {
ViewerFilter filter;
FolderFilter filter;
String prefsKey;

FolderFilterAction(FolderType type) {
setText(StringUtils.escapeAmpersandsInText(type.getLabel()));
setChecked(true);
filter = new FolderFilter(type);
setText(StringUtils.escapeAmpersandsInText(type.getLabel()));
prefsKey = "modelTreeFolderHidden_" + type.getName(); //$NON-NLS-1$

boolean hidden = ArchiPlugin.PREFERENCES.getBoolean(prefsKey);
setChecked(!hidden);
if(hidden) {
getViewer().addFilter(filter);
}
}

@Override
Expand All @@ -597,21 +605,40 @@ public void run() {
else {
getViewer().addFilter(filter);
}

ArchiPlugin.PREFERENCES.setValue(prefsKey, !isChecked());
}
}

MenuManager filterMenu = new MenuManager(Messages.TreeModelView_5);
manager.add(filterMenu);

filterMenu.add(new FolderFilterAction(FolderType.STRATEGY));
filterMenu.add(new FolderFilterAction(FolderType.BUSINESS));
filterMenu.add(new FolderFilterAction(FolderType.APPLICATION));
filterMenu.add(new FolderFilterAction(FolderType.TECHNOLOGY));
filterMenu.add(new FolderFilterAction(FolderType.MOTIVATION));
filterMenu.add(new FolderFilterAction(FolderType.IMPLEMENTATION_MIGRATION));
filterMenu.add(new FolderFilterAction(FolderType.OTHER));
filterMenu.add(new FolderFilterAction(FolderType.RELATIONS));
filterMenu.add(new FolderFilterAction(FolderType.DIAGRAMS));
List<Action> actions = new ArrayList<>();
actions.add(new FolderFilterAction(FolderType.STRATEGY));
actions.add(new FolderFilterAction(FolderType.BUSINESS));
actions.add(new FolderFilterAction(FolderType.APPLICATION));
actions.add(new FolderFilterAction(FolderType.TECHNOLOGY));
actions.add(new FolderFilterAction(FolderType.MOTIVATION));
actions.add(new FolderFilterAction(FolderType.IMPLEMENTATION_MIGRATION));
actions.add(new FolderFilterAction(FolderType.OTHER));
actions.add(new FolderFilterAction(FolderType.RELATIONS));
actions.add(new FolderFilterAction(FolderType.DIAGRAMS));

for(Action action : actions) {
filterMenu.add(action);
}

filterMenu.add(new Separator());

filterMenu.add(new Action(Messages.TreeModelView_6) {
@Override
public void run() {
for(Action action : actions) {
action.setChecked(true);
action.run();
}
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TreeModelView_2=Model Tree
TreeModelView_3=Collapse
TreeModelView_4=Expand
TreeModelView_5=Visible Folders
TreeModelView_6=Show All

TreeModelViewerDragDropHandler_0=Move Elements

Binary file modified com.archimatetool.help/help/Images/model-tree-folderfilter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion com.archimatetool.help/help/Text/model_tree_working.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h2>Drill Down</h2>

<h2>Hiding Folders</h2>

<p>It is possible to hide top-level folders in the Model Tree. A common use case is that the "Relations" folder's contents might get very long and unwieldy. To hide a folder click the drop-down menu in the Model Tree toolbar and tick or untick the folder you wish to hide or show in the "Visible Folders" sub-menu.</p>
<p>It's possible to hide top-level folders in the Model Tree. A common use case is that the "Relations" folder's contents might get very big and unwieldy. To hide a folder, click the drop-down menu in the Model Tree toolbar and check or uncheck the folder you wish to hide or show in the "Visible Folders" sub-menu. Note that these settings persist between sessions and when closing and re-opening the Model Tree.</p>
<img src="../Images/model-tree-folderfilter.png"/>
<p class="caption">Showing or hiding top-level folders</p>

Expand Down

0 comments on commit c29f922

Please sign in to comment.