Search in sources :

Example 1 with CustomOutlineFiltersDialog

use of org.erlide.ui.editors.erl.outline.filters.CustomOutlineFiltersDialog in project erlide_eclipse by erlang.

the class ShowCustomOutlineFiltersDialogHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Object activePart = HandlerUtil.getVariable(event, "activePart");
    final String targetId;
    final Shell shell;
    PatternFilter patternFilter;
    StructuredViewer viewer;
    if (activePart instanceof ContentOutline) {
        final ContentOutline outline = (ContentOutline) activePart;
        final ErlangOutlinePage erlangOutlinePage = outline.getAdapter(ErlangOutlinePage.class);
        if (erlangOutlinePage == null) {
            return null;
        }
        shell = outline.getSite().getShell();
        targetId = "org.eclipse.ui.views.ContentOutline";
        patternFilter = erlangOutlinePage.getPatternFilter();
        viewer = erlangOutlinePage.getTreeViewer();
    } else if (activePart instanceof CommonNavigator) {
        final CommonNavigator commonNavigator = (CommonNavigator) activePart;
        targetId = "commonNavigator";
        shell = commonNavigator.getSite().getShell();
        patternFilter = null;
        viewer = null;
    } else {
        return null;
    }
    List<String> oldUserDefinedPatterns = Lists.newArrayList();
    final Set<String> oldEnabledFilterIDs = Sets.newHashSet();
    final boolean oldAreUserDefinedPatternsEnabled = OutlineFilterUtils.loadViewDefaults(oldUserDefinedPatterns, oldEnabledFilterIDs);
    final CustomOutlineFiltersDialog dialog = new CustomOutlineFiltersDialog(shell, targetId, oldAreUserDefinedPatternsEnabled, oldUserDefinedPatterns, oldEnabledFilterIDs);
    if (!oldAreUserDefinedPatternsEnabled) {
        oldUserDefinedPatterns = Lists.newArrayList();
    }
    if (dialog.open() == Window.OK) {
        final boolean areUserDefinedPatternsEnabled = dialog.areUserDefinedPatternsEnabled();
        List<String> userDefinedPatterns = dialog.getUserDefinedPatterns();
        final Set<String> enabledFilterIDs = dialog.getEnabledFilterIds();
        // TODO should we support filter LRU history (as in JDT)?
        // setRecentlyChangedFilters(dialog.getFilterDescriptorChangeHistory());
        OutlineFilterUtils.storeViewDefaults(areUserDefinedPatternsEnabled, userDefinedPatterns, enabledFilterIDs);
        if (!areUserDefinedPatternsEnabled) {
            userDefinedPatterns = Lists.newArrayList();
        }
        OutlineFilterUtils.updateViewerFilters(viewer, oldUserDefinedPatterns, oldEnabledFilterIDs, userDefinedPatterns, enabledFilterIDs, patternFilter);
    }
    return null;
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) Shell(org.eclipse.swt.widgets.Shell) PatternFilter(org.erlide.ui.editors.erl.outline.filters.PatternFilter) CustomOutlineFiltersDialog(org.erlide.ui.editors.erl.outline.filters.CustomOutlineFiltersDialog) ContentOutline(org.eclipse.ui.views.contentoutline.ContentOutline) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

Aggregations

StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)1 Shell (org.eclipse.swt.widgets.Shell)1 CommonNavigator (org.eclipse.ui.navigator.CommonNavigator)1 ContentOutline (org.eclipse.ui.views.contentoutline.ContentOutline)1 CustomOutlineFiltersDialog (org.erlide.ui.editors.erl.outline.filters.CustomOutlineFiltersDialog)1 PatternFilter (org.erlide.ui.editors.erl.outline.filters.PatternFilter)1