Skip to content

Commit

Permalink
Stop the Server view from collapsing when a folder is clicked on
Browse files Browse the repository at this point in the history
* Annoying scenario where the Teiid server content is first expanded then
  collapses when a folder is selected. Due to the action provider setting
  the filtering on the content, which causes a refresh and thus the
  collapse.

* Action provider should NOT affect the content

* PreviewOptionContributor
 * Intermediary between the two providers, allowing then to affect each
   other but not directly referencing each other
 * Preview option flags bound up in this one class

* TeiidServerContentProvider
 * Implements ICommonContentProvider so its parent provider initialises
   it correctly
 * Refactors re-expand routine to a method so that the setting of the
   preview options re-expands after the refresh

* TeiidServerContainerNode
 * Rather than use viewer.setFilters which causes a refresh, adds the
   filtering directly to the content's logic. Since setting the preview
   options causes a rebuilding of the content, there is little reason to
   refresh again just to filter
  • Loading branch information
Paul Richardson committed Jun 28, 2013
1 parent a4085ec commit bcae003
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.teiid.designer.runtime.ui.views;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.Action;
Expand All @@ -20,12 +19,9 @@
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.CommonViewer;
Expand Down Expand Up @@ -63,56 +59,9 @@ public class TeiidServerActionProvider extends CommonActionProvider {
* Prefix for language NLS properties
*/
private static final String PREFIX = I18nUtil.getPropertyPrefix(TeiidServerActionProvider.class);

/**
* A <code>ViewerFilter</code> that hides Preview Data Sources.
*/
private static final ViewerFilter PREVIEW_DATA_SOURCE_FILTER = new ViewerFilter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer,
Object parentElement,
Object element) {
ITeiidDataSource dataSource = RuntimeAssistant.adapt(element, ITeiidDataSource.class);
if (dataSource != null && dataSource.isPreview()) return false;

return true;
}
};

/**
* A <code>ViewerFilter</code> that hides Preview VDBs.
*/
private static final ViewerFilter PREVIEW_VDB_FILTER = new ViewerFilter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer,
Object parentElement,
Object element) {
ITeiidVdb vdb = RuntimeAssistant.adapt(element, ITeiidVdb.class);
if (vdb != null && vdb.isPreviewVdb()) return false;

return true;
}
};

/**
* Memento info for saving and restoring menu state from session to session
*/
private static final String MENU_MEMENTO = "menu-settings"; //$NON-NLS-1$
private static final String SHOW_PREVIEW_VDBS = "show-preview-vdbs"; //$NON-NLS-1$
private static final String SHOW_PREVIEW_DATA_SOURCES = "show-preview-data-sources"; //$NON-NLS-1$

private ICommonActionExtensionSite actionSite;

private CommonViewer viewer;

/**
Expand Down Expand Up @@ -158,7 +107,9 @@ public boolean select(Viewer viewer,
private IAction showPreviewDataSourcesAction;

private IAction enablePreviewAction;


private final TeiidServerPreviewOptionContributor previewOptionContributor;

private IMenuListener enablePreviewActionListener = new IMenuListener() {

@Override
Expand All @@ -169,21 +120,12 @@ public void menuAboutToShow( IMenuManager manager ) {

private ISelectionProvider selectionProvider;

/**
* <code>true</code> if the viewer should show preview VDBs
*/
private boolean showPreviewVdbs;

/**
* <code>true</code> if the viewer should show preview data sources
*/
private boolean showPreviewDataSources;

/**
* Create instance
*/
public TeiidServerActionProvider() {
super();
previewOptionContributor = TeiidServerPreviewOptionContributor.getDefault();
}

@Override
Expand All @@ -198,7 +140,6 @@ public void init(ICommonActionExtensionSite aSite) {
ICommonViewerWorkbenchSite wsSite = (ICommonViewerWorkbenchSite)site;
selectionProvider = wsSite.getSelectionProvider();
initActions();
updateViewerFilters();
}
}
}
Expand Down Expand Up @@ -234,39 +175,14 @@ private boolean isPreviewEnabled() {
PreviewManager previewManager = getServerManager().getPreviewManager();
return ((previewManager != null) && previewManager.isPreviewEnabled());
}

/**
* Applies the current viewer filters.
*/
private void updateViewerFilters() {
List<ViewerFilter> filters = new ArrayList<ViewerFilter>(3);

if (!this.showPreviewDataSources) {
filters.add(PREVIEW_DATA_SOURCE_FILTER);
}

if (!this.showPreviewVdbs) {
filters.add(PREVIEW_VDB_FILTER);
}

// set new content filters
this.viewer.setFilters(filters.toArray(new ViewerFilter[filters.size()]));
}

/**
* Handler for when the show preview VDBs menu action is selected
* Handler for when the show preview options menu actions are selected
*/
private void toggleShowPreviewVdbs() {
this.showPreviewVdbs = !this.showPreviewVdbs;
updateViewerFilters();
}

/**
* Handler for when the show preview data sources menu action is selected
*/
private void toggleShowPreviewDataSources() {
this.showPreviewDataSources = !this.showPreviewDataSources;
updateViewerFilters();
private void toggleShowPreviewOptions() {
previewOptionContributor.setShowPreviewOptions(
showPreviewDataSourcesAction.isChecked(),
showPreviewVdbsAction.isChecked());
}

/*
Expand Down Expand Up @@ -435,7 +351,7 @@ private void fillLocalPullDown( IMenuManager menuMgr ) {
showPreviewVdbsAction = new Action(getString("showPreviewVdbsMenuItem"), SWT.TOGGLE) { //$NON-NLS-1$
@Override
public void run() {
toggleShowPreviewVdbs();
toggleShowPreviewOptions();
}
};
}
Expand All @@ -446,13 +362,13 @@ public void run() {
getString("showPreviewDataSourcesMenuItem"), SWT.TOGGLE) { //$NON-NLS-1$
@Override
public void run() {
toggleShowPreviewDataSources();
toggleShowPreviewOptions();
}
};
}

showPreviewVdbsAction.setChecked(this.showPreviewVdbs);
showPreviewDataSourcesAction.setChecked(this.showPreviewDataSources);
showPreviewVdbsAction.setChecked(previewOptionContributor.isShowPreviewVdbs());
showPreviewDataSourcesAction.setChecked(previewOptionContributor.isShowPreviewDataSources());

if (enablePreviewAction == null) {
enablePreviewAction = new Action(
Expand Down Expand Up @@ -574,38 +490,4 @@ public void fillContextMenu(IMenuManager manager) {
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
}

/* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonActionProvider#saveState(org.eclipse.ui.IMemento)
*/
@Override
public void saveState(IMemento memento) {
IMemento menuMemento = memento.createChild(MENU_MEMENTO);
menuMemento.putBoolean(SHOW_PREVIEW_DATA_SOURCES, this.showPreviewDataSourcesAction.isChecked());
menuMemento.putBoolean(SHOW_PREVIEW_VDBS, this.showPreviewVdbsAction.isChecked());
super.saveState(memento);
}

private void restoreLocalPullDown(IMemento viewMemento) {
// need to check for null since first time view is opened in a new workspace there won't be previous state
if (viewMemento != null) {
IMemento menuMemento = viewMemento.getChild(MENU_MEMENTO);

// also need to check for null here if running an existing workspace that didn't have this memento created
if (menuMemento != null) {
this.showPreviewDataSources = menuMemento.getBoolean(SHOW_PREVIEW_DATA_SOURCES);
this.showPreviewVdbs = menuMemento.getBoolean(SHOW_PREVIEW_VDBS);
}
}
}

/* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonActionProvider#restoreState(org.eclipse.ui.IMemento)
*/
@Override
public void restoreState(IMemento aMemento) {
restoreLocalPullDown(aMemento);
updateViewerFilters();
super.restoreState(aMemento);
}
}

0 comments on commit bcae003

Please sign in to comment.