Author: scabanovich
Date: 2007-08-30 10:45:19 -0400 (Thu, 30 Aug 2007)
New Revision: 3409
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/ViewConstants.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/SeamViewLayoutActionGroup.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/AbstractSeamContentProvider.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamJarFilter.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamLabelProvider.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/ScopePresentationActionProvider.java
Log:
JBIDE-667
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/AbstractSeamContentProvider.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/AbstractSeamContentProvider.java 2007-08-30
09:39:59 UTC (rev 3408)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/AbstractSeamContentProvider.java 2007-08-30
14:45:19 UTC (rev 3409)
@@ -24,10 +24,16 @@
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.navigator.ICommonContentExtensionSite;
+import org.eclipse.ui.navigator.ICommonContentProvider;
+import org.eclipse.ui.navigator.IExtensionStateModel;
import org.jboss.tools.seam.core.IRole;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
@@ -55,27 +61,71 @@
*
* @author Viacheslav Kabanovich
*/
-public abstract class AbstractSeamContentProvider implements ITreeContentProvider,
ISeamProjectChangeListener {
+public abstract class AbstractSeamContentProvider implements ITreeContentProvider,
ISeamProjectChangeListener, ICommonContentProvider {
protected Viewer viewer;
IResourceChangeListener listener = new ResourceChangeListener();
Set<ISeamProject> processed = new HashSet<ISeamProject>();
-
+ private IExtensionStateModel fStateModel;
+ IPropertyChangeListener scopePropertyListener;
+ IPropertyChangeListener layoutPropertyListener;
+ boolean isFlatLayout = true;
+ boolean isScopeLable = false;
+
public AbstractSeamContentProvider() {}
+
+ public void init(ICommonContentExtensionSite commonContentExtensionSite) {
+ fStateModel = commonContentExtensionSite.getExtensionStateModel();
+ IMemento memento = commonContentExtensionSite.getMemento();
+ restoreState(memento);
+ scopePropertyListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (ViewConstants.SCOPE_PRESENTATION.equals(event.getProperty())) {
+ if (event.getNewValue() != null) {
+ boolean newValue = ((Boolean) event.getNewValue()).booleanValue();
+ setIsScopeLable(newValue);
+ }
+ }
+ }
+ };
+ fStateModel.addPropertyChangeListener(scopePropertyListener);
+
+ layoutPropertyListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (ViewConstants.PACKAGE_STRUCTURE.equals(event.getProperty())) {
+ if (event.getNewValue() != null) {
+ boolean newValue = ((Boolean)event.getNewValue()).booleanValue();
+ setIsFlatLayout(newValue);
+ }
+ }
+ }
+ };
+ fStateModel.addPropertyChangeListener(layoutPropertyListener);
+
+ }
+
+ void setIsFlatLayout(boolean b) {
+ isFlatLayout = b;
+ }
+
+ void setIsScopeLable(boolean b) {
+ isScopeLable = b;
+ }
+
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
boolean isNotShowingScopeNodes() {
- return ScopePresentationActionProvider.isScopePresentedAsLabel();
+ return isScopeLable; // ScopePresentationActionProvider.isScopePresentedAsLabel();
// if(viewer == null) return false;
// Boolean b = (Boolean)viewer.getData("scopeAsNode");
// return b != null && b.booleanValue();
}
boolean isPackageStructureFlat() {
- return ScopePresentationActionProvider.isPackageStructureFlat();
+ return isFlatLayout; //ScopePresentationActionProvider.isPackageStructureFlat();
}
public boolean hasChildren(Object element) {
@@ -183,17 +233,6 @@
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
}
- public void dispose() {
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
- viewer = null;
- if(processed != null) {
- for (ISeamProject p : processed) {
- p.removeSeamProjectListener(this);
- }
- processed.clear();
- }
- }
-
class ResourceChangeListener implements IResourceChangeListener {
ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
@@ -232,4 +271,25 @@
}
+ public void restoreState(IMemento memento) {
+ }
+
+ public void saveState(IMemento memento) {
+ }
+
+ public void dispose() {
+ fStateModel.removePropertyChangeListener(layoutPropertyListener);
+ fStateModel.removePropertyChangeListener(scopePropertyListener);
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
+ viewer = null;
+ if(processed != null) {
+ for (ISeamProject p : processed) {
+ p.removeSeamProjectListener(this);
+ }
+ processed.clear();
+ }
+ fStateModel.removePropertyChangeListener(layoutPropertyListener);
+ fStateModel.removePropertyChangeListener(scopePropertyListener);
+ }
+
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamJarFilter.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamJarFilter.java 2007-08-30
09:39:59 UTC (rev 3408)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamJarFilter.java 2007-08-30
14:45:19 UTC (rev 3409)
@@ -52,6 +52,9 @@
for (ISeamComponent c : p.getComponents()) {
if(isUserDefinedComponent(c)) return true;
}
+ for (ISeamPackage c : p.getPackages().values()) {
+ if(isUserDefinedPackage(c)) return true;
+ }
return false;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamLabelProvider.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamLabelProvider.java 2007-08-30
09:39:59 UTC (rev 3408)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/SeamLabelProvider.java 2007-08-30
14:45:19 UTC (rev 3409)
@@ -15,11 +15,19 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.internal.ui.navigator.IExtensionStateConstants.Values;
+import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.ICommonContentExtensionSite;
+import org.eclipse.ui.navigator.ICommonLabelProvider;
+import org.eclipse.ui.navigator.IExtensionStateModel;
import org.jboss.tools.seam.core.IRole;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
@@ -35,9 +43,55 @@
/**
* @author Viacheslav Kabanovich
*/
-public class SeamLabelProvider extends LabelProvider {
+public class SeamLabelProvider extends LabelProvider implements ICommonLabelProvider {
+ private IExtensionStateModel fStateModel;
+ private AbstractSeamContentProvider contentProvider;
+
+ boolean isFlatLayout = true;
+ boolean isScopeLable = false;
+
+ IPropertyChangeListener scopePropertyListener;
+ IPropertyChangeListener layoutPropertyListener;
+
JavaElementImageProvider jip = new JavaElementImageProvider();
+ public void init(ICommonContentExtensionSite commonContentExtensionSite) {
+ fStateModel = commonContentExtensionSite.getExtensionStateModel();
+ contentProvider = (AbstractSeamContentProvider)
commonContentExtensionSite.getExtension().getContentProvider();
+
+ scopePropertyListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (ViewConstants.SCOPE_PRESENTATION.equals(event.getProperty())) {
+ if (event.getNewValue() != null) {
+ boolean newValue = ((Boolean) event.getNewValue()).booleanValue();
+ setIsScopeLable(newValue);
+ }
+ }
+ }
+ };
+ fStateModel.addPropertyChangeListener(scopePropertyListener);
+
+ layoutPropertyListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (ViewConstants.PACKAGE_STRUCTURE.equals(event.getProperty())) {
+ if (event.getNewValue() != null) {
+ boolean newValue = ((Boolean)event.getNewValue()).booleanValue();
+ setIsFlatLayout(newValue);
+ }
+ }
+ }
+ };
+ fStateModel.addPropertyChangeListener(layoutPropertyListener);
+ }
+
+ void setIsFlatLayout(boolean b) {
+ isFlatLayout = b;
+ }
+
+ void setIsScopeLable(boolean b) {
+ isScopeLable = b;
+ }
+
public String getText(Object element) {
if(element instanceof IWorkspaceRoot) {
return "";
@@ -46,7 +100,7 @@
} else if(element instanceof ISeamScope) {
return ((ISeamScope)element).getType().getLabel();
} else if(element instanceof ISeamPackage) {
- if(ScopePresentationActionProvider.isPackageStructureFlat()) {
+ if(isFlatLayout/* ScopePresentationActionProvider.isPackageStructureFlat()*/) {
return ((ISeamPackage)element).getQualifiedName();
} else {
return ((ISeamPackage)element).getName();
@@ -60,7 +114,7 @@
name = name.substring(lastIndexOf+1); // temp fix for JBIDE-644; shouldn't need
to do this here. shold be a method to getShortName or similar but ISeamComponent extends
ISeamContextVariable so ended up being weird to do clean.
}
- if(ScopePresentationActionProvider.isScopePresentedAsLabel()) {
+ if(isScopeLable /* ScopePresentationActionProvider.isScopePresentedAsLabel()*/) {
name += " (" + ((ISeamScope)c.getParent()).getType().getLabel() +
")";
}
return name;
@@ -115,4 +169,20 @@
return
PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
}
+ public void restoreState(IMemento memento) {
+ }
+
+ public void saveState(IMemento memento) {
+ }
+
+ public String getDescription(Object anElement) {
+ return "";
+ }
+
+ public void dispose() {
+ super.dispose();
+ fStateModel.removePropertyChangeListener(layoutPropertyListener);
+ fStateModel.removePropertyChangeListener(scopePropertyListener);
+ }
+
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/ViewConstants.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/ViewConstants.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/ViewConstants.java 2007-08-30
14:45:19 UTC (rev 3409)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.views;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ */
+public interface ViewConstants {
+ public String SCOPE_PRESENTATION = "seam.scopePresentation";
+ public String PACKAGE_STRUCTURE = "seam.packageStructure";
+
+ public String SCOPE_AS_LABEL = "label";
+ public String SCOPE_AS_NODE = "node";
+ public String PACKAGES_FLAT = "flat";
+ public String PACKAGES_HIERARCHICAL = "hierarchical";
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/ScopePresentationActionProvider.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/ScopePresentationActionProvider.java 2007-08-30
09:39:59 UTC (rev 3408)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/ScopePresentationActionProvider.java 2007-08-30
14:45:19 UTC (rev 3409)
@@ -10,37 +10,89 @@
******************************************************************************/
package org.jboss.tools.seam.ui.views.actions;
+import java.util.Arrays;
+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.jface.action.ContributionItem;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.IExtensionActivationListener;
+import org.eclipse.ui.navigator.IExtensionStateModel;
+import org.eclipse.ui.navigator.INavigatorActivationService;
import org.jboss.tools.seam.core.SeamPreferences;
+import org.jboss.tools.seam.ui.views.ViewConstants;
/**
* Action provider for Seam Components view.
* @author Viacheslav Kabanovich
*/
-public class ScopePresentationActionProvider extends CommonActionProvider {
- public static String SCOPE_PRESENTATION = "seam.scopePresentation";
- public static String PACKAGE_STRUCTURE = "seam.packageStructure";
-
- public static boolean isScopePresentedAsLabel() {
- String s = SeamPreferences.getInstancePreference(SCOPE_PRESENTATION);
- return "label".equals(s);
+public class ScopePresentationActionProvider extends CommonActionProvider implements
ViewConstants {
+
+ private ICommonActionExtensionSite fExtensionSite;
+ IExtensionStateModel stateModel;
+ private String fExtensionId;
+ private IActionBars fActionBars;
+ private boolean fEnabled = false;
+ SeamViewLayoutActionGroup actionGroup;
+
+ private IExtensionActivationListener fMenuUpdater= new IExtensionActivationListener() {
+
+ public void onExtensionActivation(String viewerId, String[] theNavigatorExtensionIds,
boolean isCurrentlyActive) {
+
+ if (fExtensionSite != null && fActionBars != null) {
+
+ int search= Arrays.binarySearch(theNavigatorExtensionIds, fExtensionId);
+ if (search > -1) {
+ if (isMyViewer(viewerId)) {
+ if (wasEnabled(isCurrentlyActive))
+ actionGroup.fillActionBars(fActionBars);
+
+ else
+ if (wasDisabled(isCurrentlyActive)) {
+ actionGroup.unfillActionBars(fActionBars);
+ }
+ // else no change
+ }
+ fEnabled = isCurrentlyActive;
+ }
+ }
+
+ }
+
+ private boolean isMyViewer(String viewerId) {
+ String myViewerId= fExtensionSite.getViewSite().getId();
+ return myViewerId != null && myViewerId.equals(viewerId);
+ }
+
+ private boolean wasDisabled(boolean isActive) {
+ return fEnabled && !isActive;
+ }
+
+ private boolean wasEnabled(boolean isActive) {
+ return !fEnabled && isActive;
+ }
+ };
+
+
+ public ScopePresentationActionProvider() {}
+
+ public void init(ICommonActionExtensionSite site) {
+ super.init(site);
+ fExtensionSite = site;
+ stateModel = site.getExtensionStateModel();
+ actionGroup = new SeamViewLayoutActionGroup(fExtensionSite.getStructuredViewer(),
stateModel);
+ INavigatorActivationService activationService=
fExtensionSite.getContentService().getActivationService();
+ activationService.addExtensionActivationListener(fMenuUpdater);
+ fExtensionId = fExtensionSite.getExtensionId();
+ fEnabled = true;
}
-
- public static boolean isPackageStructureFlat() {
- return true;
+
+ public void setPackageStructureFlat(boolean s) {
+ IEclipsePreferences p = SeamPreferences.getInstancePreferences();
+ p.put(PACKAGE_STRUCTURE, s ? "flat" : "hierarchical");
}
public void setScopePresentedAsLabel(boolean s) {
@@ -48,78 +100,20 @@
p.put(SCOPE_PRESENTATION, s ? "label" : "node");
}
- public ScopePresentationActionProvider() {}
-
- public void fillContextMenu(IMenuManager menu) {
- }
-
public void fillActionBars(IActionBars actionBars) {
- if(scopePresentation == null) {
- scopePresentation = new ScopePresentationContribution();
- IMenuManager menuManager = actionBars.getMenuManager();
- String SEP_NAME = "aaa";
- if(menuManager.find(IWorkbenchActionConstants.MB_ADDITIONS) != null)
- menuManager.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS, new
Separator(SEP_NAME));
- else
- menuManager.add(new Separator(SEP_NAME));
- menuManager.appendToGroup(SEP_NAME, scopePresentation);
- actionBars.updateActionBars();
- }
+ fActionBars = actionBars;
+ actionGroup.fillActionBars(actionBars);
}
- ScopePresentationContribution scopePresentation = null;
- boolean scopeAsNode = !isScopePresentedAsLabel();
+ boolean isFlatLayout = true;
+ boolean isScopeLable = false;
- class ScopePresentationContribution extends ContributionItem {
- boolean filled = false;
- public void fill(Menu menu, int index) {
- if(filled) return;
- filled = true;
- MenuItem item = new MenuItem(menu, SWT.CASCADE);
- item.setText("Scope Presentation");
- Menu smenu = new Menu(item);
- item.setMenu(smenu);
- final MenuItem item1 = new MenuItem(smenu, SWT.RADIO);
- item1.setText("As node");
- item1.setSelection(scopeAsNode);
- item1.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- public void widgetSelected(SelectionEvent e) {
- if(item1.getSelection() && !scopeAsNode) {
- scopeAsNode = true;
- setUpViewer();
- }
- }
-
- });
- final MenuItem item2 = new MenuItem(smenu, SWT.RADIO);
- item2.setText("As label");
- item2.setSelection(!scopeAsNode);
- item2.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- public void widgetSelected(SelectionEvent e) {
- if(item2.getSelection() && scopeAsNode) {
- scopeAsNode = false;
- setUpViewer();
- }
- }
-
- });
- }
-
- }
-
public void dispose() {
- scopePresentation = null;
super.dispose();
+ fExtensionSite.getContentService().getActivationService().removeExtensionActivationListener(fMenuUpdater);
}
- void setUpViewer() {
- setScopePresentedAsLabel(!scopeAsNode);
+ void updateViewer() {
BusyIndicator.showWhile(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell().getDisplay(),
new Runnable() {
@@ -127,6 +121,7 @@
try {
getActionSite().getStructuredViewer().refresh();
} catch (Exception e2) {
+ e2.printStackTrace();
//ignore
}
}
@@ -134,4 +129,53 @@
);
}
+ public void restoreState(IMemento memento) {
+ boolean isCurrentLayoutFlat = true;
+ String state = null;
+ if (memento != null)
+ state = memento.getString("seam-isFlatLayout");
+
+ if (state == null) {
+ state = SeamPreferences.getInstancePreference(PACKAGE_STRUCTURE);
+ }
+
+ isCurrentLayoutFlat = !(PACKAGES_HIERARCHICAL.equals(state));
+
+ setFlatLayout(isCurrentLayoutFlat);
+
+ boolean isCurrentScopeLabel = false;
+ state = null;
+ if (memento != null)
+ state = memento.getString("seam-isScopeLabel");
+
+ if (state == null) {
+ state = SeamPreferences.getInstancePreference(SCOPE_PRESENTATION);
+ }
+
+ isCurrentScopeLabel = !SCOPE_AS_NODE.equals(state);
+
+ setScopeLable(isCurrentScopeLabel);
+
+ }
+
+ public void saveState(IMemento aMemento) {
+ super.saveState(aMemento);
+
+ setPackageStructureFlat(isFlatLayout);
+ setScopePresentedAsLabel(isScopeLable);
+
+ }
+
+ void setFlatLayout(boolean b) {
+ isFlatLayout = b;
+ stateModel.setBooleanProperty(PACKAGE_STRUCTURE, b);
+ actionGroup.setFlatLayout(b);
+ }
+
+ void setScopeLable(boolean b) {
+ isScopeLable = b;
+ stateModel.setBooleanProperty(SCOPE_PRESENTATION, b);
+ actionGroup.setScopeLable(b);
+ }
+
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/SeamViewLayoutActionGroup.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/SeamViewLayoutActionGroup.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/views/actions/SeamViewLayoutActionGroup.java 2007-08-30
14:45:19 UTC (rev 3409)
@@ -0,0 +1,268 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.views.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.navigator.IExtensionStateModel;
+import org.jboss.tools.seam.ui.views.ViewConstants;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamViewLayoutActionGroup extends ActionGroup implements ViewConstants {
+ public static final String LAYOUT_GROUP_NAME = "layout"; //$NON-NLS-1$
+ StructuredViewer structuredViewer;
+ IExtensionStateModel stateModel;
+ private boolean hasContributedToViewMenu = false;
+
+ private IAction hierarchicalLayoutAction = null;
+ private IAction flatLayoutAction = null;
+
+ private IAction labelScopeAction = null;
+ private IAction nodeScopeAction = null;
+
+ private IMenuManager layoutSubMenu;
+ private IMenuManager scopeSubMenu;
+
+ private MenuItem hierarchicalLayoutItem = null;
+ private MenuItem flatLayoutItem = null;
+ private MenuItem labelScopeItem = null;
+ private MenuItem nodeScopeItem = null;
+
+ public SeamViewLayoutActionGroup(StructuredViewer structuredViewer,
+ IExtensionStateModel stateModel) {
+ this.structuredViewer = structuredViewer;
+ this.stateModel = stateModel;
+ }
+
+ private class CommonLayoutAction extends Action implements IAction {
+
+ private String property;
+ private final boolean value;
+
+ public CommonLayoutAction(String property, boolean value) {
+ super("", AS_RADIO_BUTTON);
+ this.property = property;
+ this.value = value;
+ }
+
+ public void run() {
+ if (stateModel.getBooleanProperty(property) != value) {
+ stateModel.setBooleanProperty(property, value);
+ structuredViewer.getControl().setRedraw(false);
+ try {
+ structuredViewer.refresh();
+ } finally {
+ structuredViewer.getControl().setRedraw(true);
+ }
+ }
+ }
+ }
+
+ public void fillActionBars(IActionBars actionBars) {
+ if (!hasContributedToViewMenu) {
+
+ IMenuManager viewMenu = actionBars.getMenuManager();
+ // Create layout sub menu
+ if (layoutSubMenu == null) {
+ layoutSubMenu = new MenuManager("Seam Packages");
+ addLayoutActions(layoutSubMenu);
+ viewMenu.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS, new
Separator(LAYOUT_GROUP_NAME));
+ }
+
+ if(scopeSubMenu == null) {
+ scopeSubMenu = new MenuManager("Scope Presentation");
+ addScopeActions(scopeSubMenu);
+ }
+
+ viewMenu.appendToGroup(LAYOUT_GROUP_NAME, layoutSubMenu);
+ viewMenu.appendToGroup(LAYOUT_GROUP_NAME, scopeSubMenu);
+
+ hasContributedToViewMenu = true;
+ }
+ }
+
+ public void unfillActionBars(IActionBars actionBars) {
+ if (hasContributedToViewMenu) {
+ // Create layout sub menu
+ if (layoutSubMenu != null) {
+ actionBars.getMenuManager().remove(layoutSubMenu);
+ layoutSubMenu.dispose();
+ layoutSubMenu = null;
+ }
+
+ if (scopeSubMenu != null) {
+ actionBars.getMenuManager().remove(scopeSubMenu);
+ scopeSubMenu.dispose();
+ scopeSubMenu = null;
+ }
+
+ hasContributedToViewMenu = false;
+ }
+ }
+
+ boolean isFlatLayout = true;
+ boolean isScopeLable = false;
+
+ void setFlatLayout(boolean b) {
+ isFlatLayout = b;
+ if(flatLayoutAction == null) {
+ createActions();
+ flatLayoutAction.setChecked(b);
+ hierarchicalLayoutAction.setChecked(!b);
+ }
+ }
+
+ void setScopeLable(boolean b) {
+ isScopeLable = b;
+ if(labelScopeAction == null) {
+ createActions();
+ labelScopeAction.setChecked(b);
+ nodeScopeAction.setChecked(!b);
+ }
+ }
+
+ private void createActions() {
+ flatLayoutAction = new CommonLayoutAction(PACKAGE_STRUCTURE, true);
+ hierarchicalLayoutAction = new CommonLayoutAction(PACKAGE_STRUCTURE, false);
+ labelScopeAction = new CommonLayoutAction(SCOPE_PRESENTATION, true);
+ nodeScopeAction = new CommonLayoutAction(SCOPE_PRESENTATION, false);
+ }
+
+ protected void addLayoutActions(IMenuManager viewMenu) {
+ viewMenu.add(new ContributionItem() {
+ public void fill(Menu menu, int index) {
+ int style = SWT.RADIO;
+ MenuItem mi = new MenuItem(menu, style, index);
+ flatLayoutItem = mi;
+ mi.setText("Flat");
+ mi.setSelection(isFlatLayout);
+ mi.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (isFlatLayout) {
+ flatLayoutItem.setSelection(true);
+ return;
+ }
+ flatLayoutAction.run();
+
+ hierarchicalLayoutItem.setSelection(false);
+ flatLayoutItem.setSelection(true);
+ isFlatLayout = true;
+ e.doit = false;
+ }
+ });
+ }
+ public boolean isDynamic() {
+ return false;
+ }
+ });
+
+ viewMenu.add(new ContributionItem() {
+ public void fill(Menu menu, int index) {
+ int style = SWT.RADIO;
+ MenuItem mi = new MenuItem(menu, style, index);
+ hierarchicalLayoutItem = mi;
+ mi.setText("Hierarchical");
+ mi.setSelection(!isFlatLayout);
+ mi.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (!isFlatLayout) {
+ hierarchicalLayoutItem.setSelection(true);
+ return;
+ }
+ hierarchicalLayoutAction.run();
+
+ flatLayoutItem.setSelection(false);
+ hierarchicalLayoutItem.setSelection(true);
+ isFlatLayout = false;
+ e.doit = false;
+ }
+ });
+ }
+ public boolean isDynamic() {
+ return false;
+ }
+ });
+
+ }
+
+ protected void addScopeActions(IMenuManager viewMenu) {
+ viewMenu.add(new ContributionItem() {
+ public void fill(Menu menu, int index) {
+ int style = SWT.RADIO;
+ MenuItem mi = new MenuItem(menu, style, index);
+ labelScopeItem = mi;
+ mi.setText("Label");
+ mi.setSelection(isScopeLable);
+ mi.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (isScopeLable) {
+ labelScopeItem.setSelection(true);
+ return;
+ }
+ labelScopeAction.run();
+
+ nodeScopeItem.setSelection(false);
+ labelScopeItem.setSelection(true);
+ isScopeLable = true;
+ e.doit = false;
+ }
+ });
+ }
+ public boolean isDynamic() {
+ return false;
+ }
+ });
+
+ viewMenu.add(new ContributionItem() {
+ public void fill(Menu menu, int index) {
+ int style = SWT.RADIO;
+ MenuItem mi = new MenuItem(menu, style, index);
+ nodeScopeItem = mi;
+ mi.setText("Node");
+ mi.setSelection(!isScopeLable);
+ mi.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (!isScopeLable) {
+ nodeScopeItem.setSelection(true);
+ return;
+ }
+ nodeScopeAction.run();
+
+ labelScopeItem.setSelection(false);
+ nodeScopeItem.setSelection(true);
+ isScopeLable = false;
+ e.doit = false;
+ }
+ });
+ }
+ public boolean isDynamic() {
+ return false;
+ }
+ });
+
+ }
+
+}