|
From: <caw...@us...> - 2007-07-18 21:35:20
|
Revision: 2790
http://svn.sourceforge.net/rubyeclipse/?rev=2790&view=rev
Author: cawilliams
Date: 2007-07-18 14:35:16 -0700 (Wed, 18 Jul 2007)
Log Message:
-----------
working set stuff. for the type hierarchy stuff.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMessages.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/dnd/BasicSelectionTransferDragAdapter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/SelectionTransferDragAdapter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ClearWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/EditWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/IWorkingSetActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/SelectWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/dnd/BasicSelectionTransferDragAdapter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/dnd/BasicSelectionTransferDragAdapter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/dnd/BasicSelectionTransferDragAdapter.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.dnd;
+
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.Transfer;
+
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.TransferDragSourceListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+
+import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
+
+public class BasicSelectionTransferDragAdapter extends DragSourceAdapter implements TransferDragSourceListener {
+
+ private ISelectionProvider fProvider;
+
+ public BasicSelectionTransferDragAdapter(ISelectionProvider provider) {
+ Assert.isNotNull(provider);
+ fProvider= provider;
+ }
+
+ /**
+ * @see TransferDragSourceListener#getTransfer
+ */
+ public Transfer getTransfer() {
+ return LocalSelectionTransfer.getInstance();
+ }
+
+ /* non Java-doc
+ * @see org.eclipse.swt.dnd.DragSourceListener#dragStart
+ */
+ public void dragStart(DragSourceEvent event) {
+ ISelection selection= fProvider.getSelection();
+ LocalSelectionTransfer.getInstance().setSelection(selection);
+ LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFFFFFFL);
+ event.doit= isDragable(selection);
+ }
+
+ /**
+ * Checks if the elements contained in the given selection can
+ * be dragged.
+ * <p>
+ * Subclasses may override.
+ *
+ * @param selection containing the elements to be dragged
+ */
+ protected boolean isDragable(ISelection selection) {
+ return true;
+ }
+
+
+ /* non Java-doc
+ * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData
+ */
+ public void dragSetData(DragSourceEvent event) {
+ // For consistency set the data to the selection even though
+ // the selection is provided by the LocalSelectionTransfer
+ // to the drop target adapter.
+ event.data= LocalSelectionTransfer.getInstance().getSelection();
+ }
+
+
+ /* non Java-doc
+ * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished
+ */
+ public void dragFinished(DragSourceEvent event) {
+ // Make sure we don't have to do any remaining work
+ Assert.isTrue(event.detail != DND.DROP_MOVE);
+ LocalSelectionTransfer.getInstance().setSelection(null);
+ LocalSelectionTransfer.getInstance().setSelectionSetTime(0);
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/dnd/BasicSelectionTransferDragAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/SelectionTransferDragAdapter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/SelectionTransferDragAdapter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/SelectionTransferDragAdapter.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.packageview;
+
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.rubypeople.rdt.internal.ui.dnd.BasicSelectionTransferDragAdapter;
+
+public class SelectionTransferDragAdapter extends BasicSelectionTransferDragAdapter {
+
+ public SelectionTransferDragAdapter(ISelectionProvider provider) {
+ super(provider);
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/SelectionTransferDragAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ClearWorkingSetAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ClearWorkingSetAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ClearWorkingSetAction.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.workingsets;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+
+/**
+ * Clears the selected working set in the action group's view.
+ *
+ * @since 2.0
+ */
+public class ClearWorkingSetAction extends Action {
+
+ private WorkingSetFilterActionGroup fActionGroup;
+
+ public ClearWorkingSetAction(WorkingSetFilterActionGroup actionGroup) {
+ super(WorkingSetMessages.ClearWorkingSetAction_text);
+ Assert.isNotNull(actionGroup);
+ setToolTipText(WorkingSetMessages.ClearWorkingSetAction_toolTip);
+ setEnabled(actionGroup.getWorkingSet() != null);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.CLEAR_WORKING_SET_ACTION);
+ fActionGroup= actionGroup;
+ }
+
+ /*
+ * Overrides method from Action
+ */
+ public void run() {
+ fActionGroup.setWorkingSet(null, true);
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ClearWorkingSetAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/EditWorkingSetAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/EditWorkingSetAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/EditWorkingSetAction.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.workingsets;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+
+/**
+ * Displays an IWorkingSetEditWizard for editing a working set.
+ *
+ * @since 2.1
+ */
+public class EditWorkingSetAction extends Action {
+ private IWorkbenchPartSite fSite;
+ private Shell fShell;
+ private WorkingSetFilterActionGroup fActionGroup;
+
+ public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, IWorkbenchPartSite site) {
+ this(actionGroup);
+ fSite= site;
+ }
+
+ public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) {
+ this(actionGroup);
+ fShell= shell;
+ }
+
+ private EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup) {
+ super(WorkingSetMessages.EditWorkingSetAction_text);
+ Assert.isNotNull(actionGroup);
+ setToolTipText(WorkingSetMessages.EditWorkingSetAction_toolTip);
+ setEnabled(actionGroup.getWorkingSet() != null);
+ fActionGroup= actionGroup;
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.EDIT_WORKING_SET_ACTION);
+ }
+
+ /*
+ * Overrides method from Action
+ */
+ public void run() {
+ Shell shell= getShell();
+ IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSet workingSet= fActionGroup.getWorkingSet();
+ if (workingSet == null || workingSet.isAggregateWorkingSet()) {
+ setEnabled(false);
+ return;
+ }
+ IWorkingSetEditWizard wizard= manager.createWorkingSetEditWizard(workingSet);
+ if (wizard == null) {
+ String title= WorkingSetMessages.EditWorkingSetAction_error_nowizard_title;
+ String message= WorkingSetMessages.EditWorkingSetAction_error_nowizard_message;
+ MessageDialog.openError(shell, title, message);
+ return;
+ }
+ WizardDialog dialog= new WizardDialog(shell, wizard);
+ dialog.create();
+ if (dialog.open() == Window.OK)
+ fActionGroup.setWorkingSet(wizard.getSelection(), true);
+ }
+
+ private Shell getShell() {
+ if (fSite != null) {
+ return fSite.getShell();
+ } else if (fShell != null) {
+ return fShell;
+ } else {
+ return RubyPlugin.getActiveWorkbenchShell();
+ }
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/EditWorkingSetAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/IWorkingSetActionGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/IWorkingSetActionGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/IWorkingSetActionGroup.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.workingsets;
+
+import org.eclipse.jface.action.IMenuManager;
+
+public interface IWorkingSetActionGroup {
+
+ public static final String ACTION_GROUP= "working_set_action_group"; //$NON-NLS-1$
+
+ public void fillViewMenu(IMenuManager mm);
+
+ public void cleanViewMenu(IMenuManager menuManager);
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/IWorkingSetActionGroup.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/SelectWorkingSetAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/SelectWorkingSetAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/SelectWorkingSetAction.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.workingsets;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+
+/**
+ * Displays an IWorkingSetSelectionDialog and sets the selected
+ * working set in the action group's view.
+ *
+ * @since 2.0
+ */
+public class SelectWorkingSetAction extends Action {
+ private IWorkbenchPartSite fSite;
+ private Shell fShell;
+ private WorkingSetFilterActionGroup fActionGroup;
+
+ public SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup, IWorkbenchPartSite site) {
+ this(actionGroup);
+ fSite= site;
+ }
+
+ public SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) {
+ this(actionGroup);
+ fShell= shell;
+ }
+
+ private SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup) {
+ super(WorkingSetMessages.SelectWorkingSetAction_text);
+ Assert.isNotNull(actionGroup);
+ setToolTipText(WorkingSetMessages.SelectWorkingSetAction_toolTip);
+ fActionGroup= actionGroup;
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.SELECT_WORKING_SET_ACTION);
+ }
+
+ /*
+ * Overrides method from Action
+ */
+ public void run() {
+ Shell shell= getShell();
+ IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSetSelectionDialog dialog= manager.createWorkingSetSelectionDialog(shell, false);
+ IWorkingSet workingSet= fActionGroup.getWorkingSet();
+ if (workingSet != null)
+ dialog.setSelection(new IWorkingSet[]{workingSet});
+
+ if (dialog.open() == Window.OK) {
+ IWorkingSet[] result= dialog.getSelection();
+ if (result != null && result.length > 0) {
+ fActionGroup.setWorkingSet(result[0], true);
+ manager.addRecentWorkingSet(result[0]);
+ }
+ else
+ fActionGroup.setWorkingSet(null, true);
+ }
+ }
+
+ private Shell getShell() {
+ if (fSite != null) {
+ return fSite.getShell();
+ } else if (fShell != null) {
+ return fShell;
+ } else {
+ return RubyPlugin.getActiveWorkbenchShell();
+ }
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/SelectWorkingSetAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilter.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.workingsets;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.ui.IWorkingSet;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.internal.ui.packageview.LoadPathContainer;
+
+/**
+ * Working set filter for Ruby viewers.
+ */
+public class WorkingSetFilter extends ViewerFilter {
+
+ private IWorkingSet fWorkingSet= null;
+ private IAdaptable[] fCachedWorkingSet= null;
+
+ /**
+ * Returns the working set which is used by this filter.
+ *
+ * @return the working set
+ */
+ public IWorkingSet getWorkingSet() {
+ return fWorkingSet;
+ }
+
+ /**
+ * Sets this filter's working set.
+ *
+ * @param workingSet the working set
+ */
+ public void setWorkingSet(IWorkingSet workingSet) {
+ fWorkingSet= workingSet;
+ }
+
+ /*
+ * Overrides method from ViewerFilter.
+ */
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (fWorkingSet == null || (fWorkingSet.isAggregateWorkingSet() && fWorkingSet.getElements().length == 0))
+ return true;
+
+ if (element instanceof IRubyElement)
+ return isEnclosing((IRubyElement)element);
+
+ if (element instanceof IResource)
+ return isEnclosing(((IResource)element).getFullPath());
+
+ if (element instanceof LoadPathContainer) {
+ return isEnclosing((LoadPathContainer)element);
+ }
+
+ if (element instanceof IAdaptable) {
+ IAdaptable adaptable= (IAdaptable)element;
+ IRubyElement je= (IRubyElement)adaptable.getAdapter(IRubyElement.class);
+ if (je != null)
+ return isEnclosing(je);
+
+ IResource resource= (IResource)adaptable.getAdapter(IResource.class);
+ if (resource != null)
+ return isEnclosing(resource.getFullPath());
+ }
+
+ return true;
+ }
+
+ private boolean isEnclosing(LoadPathContainer container) {
+ // check whether the containing packagefragment root is enclosed
+ Object[] roots= container.getSourceFolderRoots();
+ if (roots.length > 0)
+ return isEnclosing((ISourceFolderRoot)roots[0]);
+ return false;
+ }
+
+ /*
+ * Overrides method from ViewerFilter
+ */
+ public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
+ Object[] result= null;
+ if (fWorkingSet != null)
+ fCachedWorkingSet= fWorkingSet.getElements();
+ try {
+ result= super.filter(viewer, parent, elements);
+ } finally {
+ fCachedWorkingSet= null;
+ }
+ return result;
+ }
+
+ private boolean isEnclosing(IPath elementPath) {
+ if (elementPath == null)
+ return false;
+
+ IAdaptable[] cachedWorkingSet= fCachedWorkingSet;
+ if (cachedWorkingSet == null)
+ cachedWorkingSet= fWorkingSet.getElements();
+
+ int length= cachedWorkingSet.length;
+ for (int i= 0; i < length; i++) {
+ if (isEnclosing(cachedWorkingSet[i], elementPath))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isEnclosing(IRubyElement element) {
+ Assert.isNotNull(element);
+
+ IAdaptable[] cachedWorkingSet= fCachedWorkingSet;
+ if (cachedWorkingSet == null)
+ cachedWorkingSet= fWorkingSet.getElements();
+
+ boolean isElementPathComputed= false;
+ IPath elementPath= null; // will be lazy computed if needed
+
+ int length= cachedWorkingSet.length;
+ for (int i= 0; i < length; i++) {
+ IRubyElement scopeElement= (IRubyElement)cachedWorkingSet[i].getAdapter(IRubyElement.class);
+ if (scopeElement != null) {
+ // compare Ruby elements
+ IRubyElement searchedElement= element;
+ while (searchedElement != null) {
+ if (searchedElement.equals(scopeElement))
+ return true;
+ else {
+ if (scopeElement.getElementType() == IRubyElement.RUBY_PROJECT && searchedElement.getElementType() == IRubyElement.SOURCE_FOLDER_ROOT) {
+ ISourceFolderRoot pkgRoot= (ISourceFolderRoot)searchedElement;
+ if (pkgRoot.isExternal() && pkgRoot.isArchive()) {
+ if (((IRubyProject)scopeElement).isOnLoadpath(searchedElement))
+ return true;
+ }
+ }
+ searchedElement= searchedElement.getParent();
+ if (searchedElement != null && searchedElement.getElementType() == IRubyElement.SCRIPT) {
+ IRubyScript unit= (IRubyScript)searchedElement;
+ unit= unit.getPrimary();
+ }
+ }
+ }
+ while (scopeElement != null) {
+ if (element.equals(scopeElement))
+ return true;
+ else
+ scopeElement= scopeElement.getParent();
+ }
+ } else {
+ // compare resource paths
+ if (!isElementPathComputed) {
+ IResource elementResource= (IResource)element.getAdapter(IResource.class);
+ if (elementResource != null)
+ elementPath= elementResource.getFullPath();
+ }
+ if (isEnclosing(cachedWorkingSet[i], elementPath))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isEnclosing(IAdaptable element, IPath path) {
+ if (path == null)
+ return false;
+
+ IPath elementPath= null;
+
+ IResource elementResource= (IResource)element.getAdapter(IResource.class);
+ if (elementResource != null)
+ elementPath= elementResource.getFullPath();
+
+ if (elementPath == null) {
+ IRubyElement javaElement= (IRubyElement)element.getAdapter(IRubyElement.class);
+ if (javaElement != null)
+ elementPath= javaElement.getPath();
+ }
+
+ if (elementPath == null && element instanceof IStorage)
+ elementPath= ((IStorage)element).getFullPath();
+
+ if (elementPath == null)
+ return false;
+
+ if (elementPath.isPrefixOf(path))
+ return true;
+
+ if (path.isPrefixOf(elementPath))
+ return true;
+
+ return false;
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,346 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.workingsets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkbenchPreferenceConstants;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionGroup;
+import org.rubypeople.rdt.internal.ui.search.WorkingSetComparator;
+
+/**
+ * Working set filter actions (set / clear)
+ *
+ * @since 2.0
+ *
+ */
+public class WorkingSetFilterActionGroup extends ActionGroup implements IWorkingSetActionGroup {
+
+ private static final String TAG_WORKING_SET_NAME= "workingSetName"; //$NON-NLS-1$
+ private static final String TAG_IS_WINDOW_WORKING_SET= "isWindowWorkingSet"; //$NON-NLS-1$
+ private static final String LRU_GROUP= "workingSet_lru_group"; //$NON-NLS-1$
+
+ private final WorkingSetFilter fWorkingSetFilter;
+
+ private IWorkingSet fWorkingSet= null;
+
+ private final ClearWorkingSetAction fClearWorkingSetAction;
+ private final SelectWorkingSetAction fSelectWorkingSetAction;
+ private final EditWorkingSetAction fEditWorkingSetAction;
+
+ private IPropertyChangeListener fWorkingSetListener;
+ private IPropertyChangeListener fChangeListener;
+
+ private int fLRUMenuCount;
+ private IMenuManager fMenuManager;
+ private IMenuListener fMenuListener;
+ private List fContributions= new ArrayList();
+ private final IWorkbenchPage fWorkbenchPage;
+ private boolean fAllowWindowWorkingSetByDefault;
+
+ public WorkingSetFilterActionGroup(IWorkbenchPartSite site, IPropertyChangeListener changeListener) {
+ Assert.isNotNull(site);
+ Assert.isNotNull(changeListener);
+
+ fChangeListener= changeListener;
+ fWorkbenchPage= site.getPage();
+ fAllowWindowWorkingSetByDefault= true;
+ fClearWorkingSetAction= new ClearWorkingSetAction(this);
+ fSelectWorkingSetAction= new SelectWorkingSetAction(this, site);
+ fEditWorkingSetAction= new EditWorkingSetAction(this, site);
+
+ fWorkingSetListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ doPropertyChange(event);
+ }
+ };
+ fWorkingSetFilter= new WorkingSetFilter();
+
+ IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
+ manager.addPropertyChangeListener(fWorkingSetListener);
+
+ if (useWindowWorkingSetByDefault()) {
+ setWorkingSet(site.getPage().getAggregateWorkingSet(), false);
+ }
+ }
+
+ public WorkingSetFilterActionGroup(Shell shell, IWorkbenchPage page, IPropertyChangeListener changeListener) {
+ Assert.isNotNull(shell);
+ Assert.isNotNull(changeListener);
+
+ fWorkbenchPage= page;
+ fAllowWindowWorkingSetByDefault= false;
+ fChangeListener= changeListener;
+ fClearWorkingSetAction= new ClearWorkingSetAction(this);
+ fSelectWorkingSetAction= new SelectWorkingSetAction(this, shell);
+ fEditWorkingSetAction= new EditWorkingSetAction(this, shell);
+
+ fWorkingSetListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ doPropertyChange(event);
+ }
+ };
+
+ fWorkingSetFilter= new WorkingSetFilter();
+
+ IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
+ manager.addPropertyChangeListener(fWorkingSetListener);
+
+ setWorkingSet(null, false);
+ }
+
+ /**
+ * Returns whether the current working set filters the given element
+ *
+ * @param parent the parent
+ * @param object the element to test
+ * @return the working set
+ */
+ public boolean isFiltered(Object parent, Object object) {
+ if (fWorkingSetFilter == null)
+ return false;
+ return !fWorkingSetFilter.select(null, parent, object);
+ }
+
+
+ /**
+ * Returns the working set which is used by the filter.
+ *
+ * @return the working set
+ */
+ public IWorkingSet getWorkingSet() {
+ return fWorkingSet;
+ }
+
+ /**
+ * Sets this filter's working set.
+ *
+ * @param workingSet the working set
+ * @param refreshViewer Indicates if the viewer should be refreshed.
+ */
+ public void setWorkingSet(IWorkingSet workingSet, boolean refreshViewer) {
+ // Update action
+ fClearWorkingSetAction.setEnabled(workingSet != null);
+ fEditWorkingSetAction.setEnabled(workingSet != null && !workingSet.isAggregateWorkingSet());
+
+ fWorkingSet= workingSet;
+
+ fWorkingSetFilter.setWorkingSet(workingSet);
+ if (refreshViewer) {
+ fChangeListener.propertyChange(new PropertyChangeEvent(this, IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null, workingSet));
+ }
+ }
+
+ /**
+ * Saves the state of the filter actions in a memento.
+ *
+ * @param memento the memento
+ */
+ public void saveState(IMemento memento) {
+ String workingSetName= ""; //$NON-NLS-1$
+ boolean isWindowWorkingSet= false;
+ if (fWorkingSet != null) {
+ if (fWorkingSet.isAggregateWorkingSet()) {
+ isWindowWorkingSet= true;
+ } else {
+ workingSetName= fWorkingSet.getName();
+ }
+ }
+ memento.putString(TAG_IS_WINDOW_WORKING_SET, Boolean.toString(isWindowWorkingSet));
+ memento.putString(TAG_WORKING_SET_NAME, workingSetName);
+ }
+
+ /**
+ * Restores the state of the filter actions from a memento.
+ * <p>
+ * Note: This method does not refresh the viewer.
+ * </p>
+ * @param memento
+ */
+ public void restoreState(IMemento memento) {
+ boolean isWindowWorkingSet;
+ if (memento.getString(TAG_IS_WINDOW_WORKING_SET) != null) {
+ isWindowWorkingSet= Boolean.valueOf(memento.getString(TAG_IS_WINDOW_WORKING_SET)).booleanValue();
+ } else {
+ isWindowWorkingSet= useWindowWorkingSetByDefault();
+ }
+ String workingSetName= memento.getString(TAG_WORKING_SET_NAME);
+ boolean hasWorkingSetName= workingSetName != null && workingSetName.length() > 0;
+
+ IWorkingSet ws= null;
+ // First handle name if present.
+ if (hasWorkingSetName) {
+ ws= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName);
+ } else if (isWindowWorkingSet && fWorkbenchPage != null) {
+ ws= fWorkbenchPage.getAggregateWorkingSet();
+ }
+ setWorkingSet(ws, false);
+ }
+
+ private boolean useWindowWorkingSetByDefault() {
+ return fAllowWindowWorkingSetByDefault && PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_WINDOW_WORKING_SET_BY_DEFAULT);
+ }
+
+
+ /* (non-Rubydoc)
+ * @see ActionGroup#fillActionBars(IActionBars)
+ */
+ public void fillActionBars(IActionBars actionBars) {
+ fillToolBar(actionBars.getToolBarManager());
+ fillViewMenu(actionBars.getMenuManager());
+ }
+
+ /**
+ * Adds the filter actions to the tool bar
+ *
+ * @param tbm the tool bar manager
+ */
+ private void fillToolBar(IToolBarManager tbm) {
+ // do nothing
+ }
+
+ /**
+ * Adds the filter actions to the menu
+ *
+ * @param mm the menu manager
+ */
+ public void fillViewMenu(IMenuManager mm) {
+ if (mm.find(IWorkingSetActionGroup.ACTION_GROUP) == null) {
+ mm.add(new Separator(IWorkingSetActionGroup.ACTION_GROUP));
+ }
+ add(mm, fSelectWorkingSetAction);
+ add(mm, fClearWorkingSetAction);
+ add(mm, fEditWorkingSetAction);
+ add(mm, new Separator());
+ add(mm, new Separator(LRU_GROUP));
+
+ fMenuManager= mm;
+ fMenuListener= new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ removePreviousLRUWorkingSetActions(manager);
+ addLRUWorkingSetActions(manager);
+ }
+ };
+ fMenuManager.addMenuListener(fMenuListener);
+ }
+
+ private void add(IMenuManager mm, IAction action) {
+ IContributionItem item= new ActionContributionItem(action);
+ mm.appendToGroup(ACTION_GROUP, item);
+ fContributions.add(item);
+ }
+
+ private void add(IMenuManager mm, IContributionItem item) {
+ mm.appendToGroup(ACTION_GROUP, item);
+ fContributions.add(item);
+ }
+
+ private void removePreviousLRUWorkingSetActions(IMenuManager mm) {
+ for (int i= 1; i < fLRUMenuCount; i++) {
+ String id= WorkingSetMenuContributionItem.getId(i);
+ IContributionItem item= mm.remove(id);
+ fContributions.remove(item);
+ }
+ }
+
+ private void addLRUWorkingSetActions(IMenuManager mm) {
+ IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getRecentWorkingSets();
+ Arrays.sort(workingSets, new WorkingSetComparator());
+
+ int currId= 1;
+ if (fWorkbenchPage != null) {
+ addLRUWorkingSetAction(mm, currId++, fWorkbenchPage.getAggregateWorkingSet());
+ }
+
+ for (int i= 0; i < workingSets.length; i++) {
+ if (!workingSets[i].isAggregateWorkingSet()) {
+ addLRUWorkingSetAction(mm, currId++, workingSets[i]);
+ }
+ }
+ fLRUMenuCount= currId;
+ }
+
+ private void addLRUWorkingSetAction(IMenuManager mm, int id, IWorkingSet workingSet) {
+ IContributionItem item= new WorkingSetMenuContributionItem(id, this, workingSet);
+ mm.insertBefore(LRU_GROUP, item);
+ fContributions.add(item);
+ }
+
+
+ public void cleanViewMenu(IMenuManager menuManager) {
+ for (Iterator iter= fContributions.iterator(); iter.hasNext();) {
+ menuManager.remove((IContributionItem)iter.next());
+ }
+ fContributions.clear();
+ fMenuManager.removeMenuListener(fMenuListener);
+ fMenuListener= null;
+ }
+
+ /* (non-Rubydoc)
+ * @see ActionGroup#dispose()
+ */
+ public void dispose() {
+ if (fMenuManager != null && fMenuListener != null)
+ fMenuManager.removeMenuListener(fMenuListener);
+
+ if (fWorkingSetListener != null) {
+ PlatformUI.getWorkbench().getWorkingSetManager().removePropertyChangeListener(fWorkingSetListener);
+ fWorkingSetListener= null;
+ }
+ fChangeListener= null; // clear the reference to the viewer
+
+ super.dispose();
+ }
+
+ /**
+ * @return Returns viewer filter always configured with the current working set.
+ */
+ public ViewerFilter getWorkingSetFilter() {
+ return fWorkingSetFilter;
+ }
+
+ /*
+ * Called by the working set change listener
+ */
+ private void doPropertyChange(PropertyChangeEvent event) {
+ String property= event.getProperty();
+ if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property)) {
+ fChangeListener.propertyChange(event);
+ } else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property)) {
+ IWorkingSet newWorkingSet= (IWorkingSet) event.getNewValue();
+ if (newWorkingSet.equals(fWorkingSet)) {
+ fChangeListener.propertyChange(event);
+ }
+ }
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetFilterActionGroup.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.workingsets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.util.Assert;
+
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Menu contribution item which shows and lets select a working set.
+ *
+ * @since 2.0
+ */
+public class WorkingSetMenuContributionItem extends ContributionItem {
+
+ private int fId;
+ private IWorkingSet fWorkingSet;
+ private WorkingSetFilterActionGroup fActionGroup;
+ private Image fImage;
+
+ /**
+ * Constructor for WorkingSetMenuContributionItem.
+ *
+ * @param id the id
+ * @param actionGroup the action group
+ * @param workingSet the working set
+ */
+ public WorkingSetMenuContributionItem(int id, WorkingSetFilterActionGroup actionGroup, IWorkingSet workingSet) {
+ super(getId(id));
+ Assert.isNotNull(actionGroup);
+ Assert.isNotNull(workingSet);
+ fId= id;
+ fActionGroup= actionGroup;
+ fWorkingSet= workingSet;
+ }
+
+ /*
+ * Overrides method from ContributionItem.
+ */
+ public void fill(Menu menu, int index) {
+ MenuItem mi= new MenuItem(menu, SWT.RADIO, index);
+
+ String name= fWorkingSet.getLabel();
+
+ mi.setText("&" + fId + " " + name); //$NON-NLS-1$ //$NON-NLS-2$
+ if (fImage == null) {
+ ImageDescriptor imageDescriptor= fWorkingSet.getImage();
+ if (imageDescriptor != null)
+ fImage= imageDescriptor.createImage();
+ }
+ mi.setImage(fImage);
+ mi.setSelection(fWorkingSet.equals(fActionGroup.getWorkingSet()));
+ mi.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
+ fActionGroup.setWorkingSet(fWorkingSet, true);
+ manager.addRecentWorkingSet(fWorkingSet);
+ }
+ });
+ }
+
+ /*
+ * @see org.eclipse.jface.action.ContributionItem#dispose()
+ * @since 3.0
+ */
+ public void dispose() {
+ if (fImage != null && !fImage.isDisposed())
+ fImage.dispose();
+ fImage= null;
+
+ super.dispose();
+ }
+
+ /*
+ * @see org.eclipse.jface.action.IContributionItem#isDynamic()
+ */
+ public boolean isDynamic() {
+ return true;
+ }
+
+ static String getId(int id) {
+ return WorkingSetMenuContributionItem.class.getName() + "." + id; //$NON-NLS-1$
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMenuContributionItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMessages.java 2007-07-18 21:25:17 UTC (rev 2789)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetMessages.java 2007-07-18 21:35:16 UTC (rev 2790)
@@ -18,7 +18,17 @@
public static String WorkingSetModel_others_name;
+ public static String ClearWorkingSetAction_text;
+ public static String ClearWorkingSetAction_toolTip;
+ public static String SelectWorkingSetAction_text;
+ public static String SelectWorkingSetAction_toolTip;
+
+ public static String EditWorkingSetAction_text;
+ public static String EditWorkingSetAction_toolTip;
+ public static String EditWorkingSetAction_error_nowizard_title;
+ public static String EditWorkingSetAction_error_nowizard_message;
+
static {
NLS.initializeMessages(BUNDLE_NAME, WorkingSetMessages.class);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|