|
From: <caw...@us...> - 2007-09-07 13:46:13
|
Revision: 3100
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3100&view=rev
Author: cawilliams
Date: 2007-09-07 06:46:11 -0700 (Fri, 07 Sep 2007)
Log Message:
-----------
first cut at a replacement for Ruby Resources View - based on JDT's Package Explorer
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.properties
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.java
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.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/IContextMenuConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyElementLabels.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyElementSorter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyUI.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/StandardRubyElementContentProvider.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/icons/full/dlcl16/collapseall.gif
trunk/org.rubypeople.rdt.ui/icons/full/elcl16/collapseall.gif
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CollapseAllAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CustomHashtable.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoResourceAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoTypeAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/IMultiElementTreeContentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerContentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerLabelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerPart.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerProblemsDecorator.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesFrameSource.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/SourceFolderProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/ToggleLinkingAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/WorkingSetAwareContentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/WorkingSetAwareLabelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/WorkingSetAwareRubyElementSorter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/viewsupport/FilterUpdater.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/viewsupport/TreeHierarchyLayoutProblemsDecorator.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ConfigureWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/OpenCloseWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/OpenPropertiesWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/RemoveWorkingSetElementAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/RubyWorkingSetUpdater.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ViewAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/ViewActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetConfigurationDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/workingsets/WorkingSetShowActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/IPackagesViewPart.java
Added: trunk/org.rubypeople.rdt.ui/icons/full/dlcl16/collapseall.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.ui/icons/full/dlcl16/collapseall.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/org.rubypeople.rdt.ui/icons/full/elcl16/collapseall.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.ui/icons/full/elcl16/collapseall.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/org.rubypeople.rdt.ui/plugin.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.properties 2007-09-07 12:27:52 UTC (rev 3099)
+++ trunk/org.rubypeople.rdt.ui/plugin.properties 2007-09-07 13:46:11 UTC (rev 3100)
@@ -33,6 +33,7 @@
PreferencePage.rdtDebuggerPreferences=Debugger
viewCategoryName=Ruby
+packagesViewName=Ruby Explorer
hierarchyViewName=Hierarchy
appearancePrefName=Appearance
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2007-09-07 12:27:52 UTC (rev 3099)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2007-09-07 13:46:11 UTC (rev 3100)
@@ -377,6 +377,13 @@
name="%viewCategoryName"
id="org.rubypeople.rdt.ui.ruby">
</category>
+ <view
+ name="%packagesViewName"
+ icon="$nl$/icons/full/ctool16/ruby.gif"
+ category="org.rubypeople.rdt.ui.ruby"
+ class="org.rubypeople.rdt.internal.ui.packageview.PackageExplorerPart"
+ id="org.rubypeople.rdt.ui.PackageExplorer">
+ </view>
<view
name="%ViewRubyResources.name"
icon="icons/full/ctool16/ruby.gif"
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java 2007-09-07 12:27:52 UTC (rev 3099)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -95,6 +95,8 @@
public static String OpenTypeHierarchyUtil_error_open_editor;
public static String OpenTypeHierarchyUtil_error_open_view;
+ public static String RubyUI_defaultDialogMessage;
+
private RubyUIMessages() {
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties 2007-09-07 12:27:52 UTC (rev 3099)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyUIMessages.properties 2007-09-07 13:46:11 UTC (rev 3100)
@@ -3,6 +3,11 @@
# All Rights Reserved.
#########################################
+#######
+## dialogs
+#######
+RubyUI_defaultDialogMessage=Select entries:
+
#########################################
# RdtUiPlugin
#########################################
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CollapseAllAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CollapseAllAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CollapseAllAction.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.action.Action;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+
+/**
+ * Collapse all nodes.
+ */
+class CollapseAllAction extends Action {
+
+ private PackageExplorerPart fPackageExplorer;
+
+ CollapseAllAction(PackageExplorerPart part) {
+ super(PackagesMessages.CollapseAllAction_label);
+ setDescription(PackagesMessages.CollapseAllAction_description);
+ setToolTipText(PackagesMessages.CollapseAllAction_tooltip);
+ RubyPluginImages.setLocalImageDescriptors(this, "collapseall.gif"); //$NON-NLS-1$
+
+ fPackageExplorer= part;
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.COLLAPSE_ALL_ACTION);
+ }
+
+ public void run() {
+ fPackageExplorer.collapseAll();
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CollapseAllAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CustomHashtable.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CustomHashtable.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CustomHashtable.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -0,0 +1,403 @@
+/*******************************************************************************
+ * 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:
+ * Peter Shipton - original hashtable implementation
+ * Nick Edgar - added element comparer support
+ *******************************************************************************/
+
+package org.rubypeople.rdt.internal.ui.packageview;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+import org.eclipse.jface.viewers.IElementComparer;
+
+/**
+ * CustomHashtable associates keys with values. Keys and values cannot be null.
+ * The size of the Hashtable is the number of key/value pairs it contains.
+ * The capacity is the number of key/value pairs the Hashtable can hold.
+ * The load factor is a float value which determines how full the Hashtable
+ * gets before expanding the capacity. If the load factor of the Hashtable
+ * is exceeded, the capacity is doubled.
+ * <p>
+ * CustomHashtable allows a custom comparator and hash code provider.
+ */
+/* package */final class CustomHashtable {
+
+ /**
+ * HashMapEntry is an internal class which is used to hold the entries of a Hashtable.
+ */
+ private static class HashMapEntry {
+ Object key, value;
+
+ HashMapEntry next;
+
+ HashMapEntry(Object theKey, Object theValue) {
+ key = theKey;
+ value = theValue;
+ }
+ }
+
+ private static final class EmptyEnumerator implements Enumeration {
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ public Object nextElement() {
+ throw new NoSuchElementException();
+ }
+ }
+
+ private class HashEnumerator implements Enumeration {
+ boolean key;
+
+ int start;
+
+ HashMapEntry entry;
+
+ HashEnumerator(boolean isKey) {
+ key = isKey;
+ start = firstSlot;
+ }
+
+ public boolean hasMoreElements() {
+ if (entry != null)
+ return true;
+ while (start <= lastSlot)
+ if (elementData[start++] != null) {
+ entry = elementData[start - 1];
+ return true;
+ }
+ return false;
+ }
+
+ public Object nextElement() {
+ if (hasMoreElements()) {
+ Object result = key ? entry.key : entry.value;
+ entry = entry.next;
+ return result;
+ } else
+ throw new NoSuchElementException();
+ }
+ }
+
+ transient int elementCount;
+
+ transient HashMapEntry[] elementData;
+
+ private float loadFactor;
+
+ private int threshold;
+
+ transient int firstSlot = 0;
+
+ transient int lastSlot = -1;
+
+ transient private IElementComparer comparer;
+
+ private static final EmptyEnumerator emptyEnumerator = new EmptyEnumerator();
+
+ /**
+ * The default capacity used when not specified in the constructor.
+ */
+ public static final int DEFAULT_CAPACITY = 13;
+
+ /**
+ * Constructs a new Hashtable using the default capacity
+ * and load factor.
+ */
+ public CustomHashtable() {
+ this(13);
+ }
+
+ /**
+ * Constructs a new Hashtable using the specified capacity
+ * and the default load factor.
+ *
+ * @param capacity the initial capacity
+ */
+ public CustomHashtable(int capacity) {
+ this(capacity, null);
+ }
+
+ /**
+ * Constructs a new hash table with the default capacity and the given
+ * element comparer.
+ *
+ * @param comparer the element comparer to use to compare keys and obtain
+ * hash codes for keys, or <code>null</code> to use the normal
+ * <code>equals</code> and <code>hashCode</code> methods
+ */
+ public CustomHashtable(IElementComparer comparer) {
+ this(DEFAULT_CAPACITY, comparer);
+ }
+
+ /**
+ * Constructs a new hash table with the given capacity and the given
+ * element comparer.
+ *
+ * @param capacity the maximum number of elements that can be added without
+ * rehashing
+ * @param comparer the element comparer to use to compare keys and obtain
+ * hash codes for keys, or <code>null</code> to use the normal
+ * <code>equals</code> and <code>hashCode</code> methods
+ */
+ public CustomHashtable(int capacity, IElementComparer comparer) {
+ if (capacity >= 0) {
+ elementCount = 0;
+ elementData = new HashMapEntry[capacity == 0 ? 1 : capacity];
+ firstSlot = elementData.length;
+ loadFactor = 0.75f;
+ computeMaxSize();
+ } else
+ throw new IllegalArgumentException();
+ this.comparer = comparer;
+ }
+
+ /**
+ * Constructs a new hash table with enough capacity to hold all keys in the
+ * given hash table, then adds all key/value pairs in the given hash table
+ * to the new one, using the given element comparer.
+ *
+ * @param table the hash table to add from
+ * @param comparer the element comparer to use to compare keys and obtain
+ * hash codes for keys, or <code>null</code> to use the normal
+ * <code>equals</code> and <code>hashCode</code> methods
+ */
+ public CustomHashtable(CustomHashtable table, IElementComparer comparer) {
+ this(table.size() * 2, comparer);
+ for (int i = table.elementData.length; --i >= 0;) {
+ HashMapEntry entry = table.elementData[i];
+ while (entry != null) {
+ put(entry.key, entry.value);
+ entry = entry.next;
+ }
+ }
+ }
+
+ private void computeMaxSize() {
+ threshold = (int) (elementData.length * loadFactor);
+ }
+
+ /**
+ * Answers if this Hashtable contains the specified object as a key
+ * of one of the key/value pairs.
+ *
+ * @param key the object to look for as a key in this Hashtable
+ * @return true if object is a key in this Hashtable, false otherwise
+ */
+ public boolean containsKey(Object key) {
+ return getEntry(key) != null;
+ }
+
+ /**
+ * Answers an Enumeration on the values of this Hashtable. The
+ * results of the Enumeration may be affected if the contents
+ * of this Hashtable are modified.
+ *
+ * @return an Enumeration of the values of this Hashtable
+ */
+ public Enumeration elements() {
+ if (elementCount == 0)
+ return emptyEnumerator;
+ return new HashEnumerator(false);
+ }
+
+ /**
+ * Answers the value associated with the specified key in
+ * this Hashtable.
+ *
+ * @param key the key of the value returned
+ * @return the value associated with the specified key, null if the specified key
+ * does not exist
+ */
+ public Object get(Object key) {
+ int index = (hashCode(key) & 0x7FFFFFFF) % elementData.length;
+ HashMapEntry entry = elementData[index];
+ while (entry != null) {
+ if (keyEquals(key, entry.key))
+ return entry.value;
+ entry = entry.next;
+ }
+ return null;
+ }
+
+ private HashMapEntry getEntry(Object key) {
+ int index = (hashCode(key) & 0x7FFFFFFF) % elementData.length;
+ HashMapEntry entry = elementData[index];
+ while (entry != null) {
+ if (keyEquals(key, entry.key))
+ return entry;
+ entry = entry.next;
+ }
+ return null;
+ }
+
+ /**
+ * Answers the hash code for the given key.
+ */
+ private int hashCode(Object key) {
+ if (comparer == null)
+ return key.hashCode();
+ else
+ return comparer.hashCode(key);
+ }
+
+ /**
+ * Compares two keys for equality.
+ */
+ private boolean keyEquals(Object a, Object b) {
+ if (comparer == null)
+ return a.equals(b);
+ else
+ return comparer.equals(a, b);
+ }
+
+ /**
+ * Answers an Enumeration on the keys of this Hashtable. The
+ * results of the Enumeration may be affected if the contents
+ * of this Hashtable are modified.
+ *
+ * @return an Enumeration of the keys of this Hashtable
+ */
+ public Enumeration keys() {
+ if (elementCount == 0)
+ return emptyEnumerator;
+ return new HashEnumerator(true);
+ }
+
+ /**
+ * Associate the specified value with the specified key in this Hashtable.
+ * If the key already exists, the old value is replaced. The key and value
+ * cannot be null.
+ *
+ * @param key the key to add
+ * @param value the value to add
+ * @return the old value associated with the specified key, null if the key did
+ * not exist
+ */
+ public Object put(Object key, Object value) {
+ if (key != null && value != null) {
+ int index = (hashCode(key) & 0x7FFFFFFF) % elementData.length;
+ HashMapEntry entry = elementData[index];
+ while (entry != null && !keyEquals(key, entry.key))
+ entry = entry.next;
+ if (entry == null) {
+ if (++elementCount > threshold) {
+ rehash();
+ index = (hashCode(key) & 0x7FFFFFFF) % elementData.length;
+ }
+ if (index < firstSlot)
+ firstSlot = index;
+ if (index > lastSlot)
+ lastSlot = index;
+ entry = new HashMapEntry(key, value);
+ entry.next = elementData[index];
+ elementData[index] = entry;
+ return null;
+ }
+ Object result = entry.value;
+ entry.key = key; // important to avoid hanging onto keys that are equal but "old" -- see bug 30607
+ entry.value = value;
+ return result;
+ } else
+ throw new NullPointerException();
+ }
+
+ /**
+ * Increases the capacity of this Hashtable. This method is sent when
+ * the size of this Hashtable exceeds the load factor.
+ */
+ private void rehash() {
+ int length = elementData.length << 1;
+ if (length == 0)
+ length = 1;
+ firstSlot = length;
+ lastSlot = -1;
+ HashMapEntry[] newData = new HashMapEntry[length];
+ for (int i = elementData.length; --i >= 0;) {
+ HashMapEntry entry = elementData[i];
+ while (entry != null) {
+ int index = (hashCode(entry.key) & 0x7FFFFFFF) % length;
+ if (index < firstSlot)
+ firstSlot = index;
+ if (index > lastSlot)
+ lastSlot = index;
+ HashMapEntry next = entry.next;
+ entry.next = newData[index];
+ newData[index] = entry;
+ entry = next;
+ }
+ }
+ elementData = newData;
+ computeMaxSize();
+ }
+
+ /**
+ * Remove the key/value pair with the specified key from this Hashtable.
+ *
+ * @param key the key to remove
+ * @return the value associated with the specified key, null if the specified key
+ * did not exist
+ */
+ public Object remove(Object key) {
+ HashMapEntry last = null;
+ int index = (hashCode(key) & 0x7FFFFFFF) % elementData.length;
+ HashMapEntry entry = elementData[index];
+ while (entry != null && !keyEquals(key, entry.key)) {
+ last = entry;
+ entry = entry.next;
+ }
+ if (entry != null) {
+ if (last == null)
+ elementData[index] = entry.next;
+ else
+ last.next = entry.next;
+ elementCount--;
+ return entry.value;
+ }
+ return null;
+ }
+
+ /**
+ * Answers the number of key/value pairs in this Hashtable.
+ *
+ * @return the number of key/value pairs in this Hashtable
+ */
+ public int size() {
+ return elementCount;
+ }
+
+ /**
+ * Answers the string representation of this Hashtable.
+ *
+ * @return the string representation of this Hashtable
+ */
+ public String toString() {
+ if (size() == 0)
+ return "{}"; //$NON-NLS-1$
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append('{');
+ for (int i = elementData.length; --i >= 0;) {
+ HashMapEntry entry = elementData[i];
+ while (entry != null) {
+ buffer.append(entry.key);
+ buffer.append('=');
+ buffer.append(entry.value);
+ buffer.append(", "); //$NON-NLS-1$
+ entry = entry.next;
+ }
+ }
+ // Remove the last ", "
+ if (elementCount > 0)
+ buffer.setLength(buffer.length() - 2);
+ buffer.append('}');
+ return buffer.toString();
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/CustomHashtable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoResourceAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoResourceAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoResourceAction.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ResourceListSelectionDialog;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+
+public class GotoResourceAction extends Action {
+
+ private PackageExplorerPart fPackageExplorer;
+
+ private static class GotoResourceDialog extends ResourceListSelectionDialog {
+ private IRubyModel fRubyModel;
+ public GotoResourceDialog(Shell parentShell, IContainer container, StructuredViewer viewer) {
+ super(parentShell, container, IResource.FILE | IResource.FOLDER | IResource.PROJECT);
+ fRubyModel= RubyCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ setTitle(PackagesMessages.GotoResource_dialog_title);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(parentShell, IRubyHelpContextIds.GOTO_RESOURCE_DIALOG);
+ }
+ protected boolean select(IResource resource) {
+ IProject project= resource.getProject();
+ try {
+ if (project.getNature(RubyCore.NATURE_ID) != null)
+ return fRubyModel.contains(resource);
+ } catch (CoreException e) {
+ // do nothing. Consider resource;
+ }
+ return true;
+ }
+ }
+
+ public GotoResourceAction(PackageExplorerPart explorer) {
+ setText(PackagesMessages.GotoResource_action_label);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.GOTO_RESOURCE_ACTION);
+ fPackageExplorer= explorer;
+ }
+
+ public void run() {
+ TreeViewer viewer= fPackageExplorer.getViewer();
+ GotoResourceDialog dialog= new GotoResourceDialog(fPackageExplorer.getSite().getShell(),
+ ResourcesPlugin.getWorkspace().getRoot(), viewer);
+ dialog.open();
+ Object[] result = dialog.getResult();
+ if (result == null || result.length == 0 || !(result[0] instanceof IResource))
+ return;
+ StructuredSelection selection= null;
+ IRubyElement element = RubyCore.create((IResource)result[0]);
+ if (element != null && element.exists())
+ selection= new StructuredSelection(element);
+ else
+ selection= new StructuredSelection(result[0]);
+ viewer.setSelection(selection, true);
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoResourceAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoTypeAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoTypeAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoTypeAction.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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.packageview;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.core.search.IRubySearchConstants;
+import org.rubypeople.rdt.core.search.SearchEngine;
+import org.rubypeople.rdt.internal.corext.util.Messages;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.util.ExceptionHandler;
+import org.rubypeople.rdt.ui.RubyUI;
+
+class GotoTypeAction extends Action {
+
+ private PackageExplorerPart fPackageExplorer;
+
+ GotoTypeAction(PackageExplorerPart part) {
+ super();
+ setText(PackagesMessages.GotoType_action_label);
+ setDescription(PackagesMessages.GotoType_action_description);
+ fPackageExplorer= part;
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.GOTO_TYPE_ACTION);
+ }
+
+ public void run() {
+ Shell shell= RubyPlugin.getActiveWorkbenchShell();
+ SelectionDialog dialog= null;
+ try {
+ dialog= RubyUI.createTypeDialog(shell, new ProgressMonitorDialog(shell),
+ SearchEngine.createWorkspaceScope(), IRubySearchConstants.TYPE, false);
+ } catch (RubyModelException e) {
+ String title= getDialogTitle();
+ String message= PackagesMessages.GotoType_error_message;
+ ExceptionHandler.handle(e, title, message);
+ return;
+ }
+
+ dialog.setTitle(getDialogTitle());
+ dialog.setMessage(PackagesMessages.GotoType_dialog_message);
+ if (dialog.open() == IDialogConstants.CANCEL_ID) {
+ return;
+ }
+
+ Object[] types= dialog.getResult();
+ if (types != null && types.length > 0) {
+ gotoType((IType) types[0]);
+ }
+ }
+
+ private void gotoType(IType type) {
+ IRubyScript cu= (IRubyScript) type.getAncestor(IRubyElement.SCRIPT);
+ IRubyElement element= null;
+ if (cu != null) {
+ element= cu.getPrimary();
+ }
+ if (element != null) {
+ PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
+ if (view != null) {
+ view.selectReveal(new StructuredSelection(element));
+ if (!element.equals(getSelectedElement(view))) {
+ MessageDialog.openInformation(fPackageExplorer.getSite().getShell(),
+ getDialogTitle(),
+ Messages.format(PackagesMessages.PackageExplorer_element_not_present, element.getElementName()));
+ }
+ }
+ }
+ }
+
+ private Object getSelectedElement(PackageExplorerPart view) {
+ return ((IStructuredSelection)view.getSite().getSelectionProvider().getSelection()).getFirstElement();
+ }
+
+ private String getDialogTitle() {
+ return PackagesMessages.GotoType_dialog_title;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/GotoTypeAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/IMultiElementTreeContentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/IMultiElementTreeContentProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/IMultiElementTreeContentProvider.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * 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.packageview;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreePath;
+
+public interface IMultiElementTreeContentProvider extends ITreeContentProvider {
+ public TreePath[] getTreePaths(Object element);
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/IMultiElementTreeContentProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -0,0 +1,377 @@
+/*******************************************************************************
+ * 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.packageview;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.OpenStrategy;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.OpenInNewWindowAction;
+import org.eclipse.ui.views.framelist.BackAction;
+import org.eclipse.ui.views.framelist.ForwardAction;
+import org.eclipse.ui.views.framelist.Frame;
+import org.eclipse.ui.views.framelist.FrameAction;
+import org.eclipse.ui.views.framelist.FrameList;
+import org.eclipse.ui.views.framelist.GoIntoAction;
+import org.eclipse.ui.views.framelist.TreeFrame;
+import org.eclipse.ui.views.framelist.UpAction;
+import org.rubypeople.rdt.core.IOpenable;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.ui.actions.CompositeActionGroup;
+import org.rubypeople.rdt.internal.ui.actions.NewWizardsActionGroup;
+import org.rubypeople.rdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup;
+import org.rubypeople.rdt.internal.ui.workingsets.ViewActionGroup;
+import org.rubypeople.rdt.internal.ui.workingsets.WorkingSetActionGroup;
+import org.rubypeople.rdt.ui.IContextMenuConstants;
+import org.rubypeople.rdt.ui.PreferenceConstants;
+import org.rubypeople.rdt.ui.actions.CustomFiltersActionGroup;
+import org.rubypeople.rdt.ui.actions.NavigateActionGroup;
+import org.rubypeople.rdt.ui.actions.RdtActionConstants;
+import org.rubypeople.rdt.ui.actions.RubySearchActionGroup;
+
+class PackageExplorerActionGroup extends CompositeActionGroup {
+
+ private PackageExplorerPart fPart;
+
+ private FrameList fFrameList;
+ private GoIntoAction fZoomInAction;
+ private BackAction fBackAction;
+ private ForwardAction fForwardAction;
+ private UpAction fUpAction;
+ private GotoTypeAction fGotoTypeAction;
+// private GotoPackageAction fGotoPackageAction;
+ private GotoResourceAction fGotoResourceAction;
+ private CollapseAllAction fCollapseAllAction;
+
+
+ private ToggleLinkingAction fToggleLinkingAction;
+
+// private RefactorActionGroup fRefactorActionGroup;
+ private NavigateActionGroup fNavigateActionGroup;
+ private ViewActionGroup fViewActionGroup;
+
+ private CustomFiltersActionGroup fCustomFiltersActionGroup;
+
+ private IAction fGotoRequiredProjectAction;
+
+ public PackageExplorerActionGroup(PackageExplorerPart part) {
+ super();
+ fPart= part;
+ TreeViewer viewer= part.getViewer();
+
+ IPropertyChangeListener workingSetListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ doWorkingSetChanged(event);
+ }
+ };
+
+ IWorkbenchPartSite site = fPart.getSite();
+ setGroups(new ActionGroup[] {
+ new NewWizardsActionGroup(site),
+ fNavigateActionGroup= new NavigateActionGroup(fPart),
+// new CCPActionGroup(fPart),
+ new GenerateBuildPathActionGroup(fPart),
+// new GenerateActionGroup(fPart),
+// fRefactorActionGroup= new RefactorActionGroup(fPart),
+// new ImportActionGroup(fPart),
+// new BuildActionGroup(fPart),
+ new RubySearchActionGroup(fPart),
+// new ProjectActionGroup(fPart),
+ fViewActionGroup= new ViewActionGroup(fPart.getRootMode(), workingSetListener, site),
+ fCustomFiltersActionGroup= new CustomFiltersActionGroup(fPart, viewer),
+// new LayoutActionGroup(fPart),
+ // the working set action group must be created after the project action group
+ new WorkingSetActionGroup(fPart)});
+
+
+ fViewActionGroup.fillFilters(viewer);
+
+ PackagesFrameSource frameSource= new PackagesFrameSource(fPart);
+ fFrameList= new FrameList(frameSource);
+ frameSource.connectTo(fFrameList);
+
+ fZoomInAction= new GoIntoAction(fFrameList);
+ fBackAction= new BackAction(fFrameList);
+ fForwardAction= new ForwardAction(fFrameList);
+ fUpAction= new UpAction(fFrameList);
+
+ fGotoTypeAction= new GotoTypeAction(fPart);
+// fGotoPackageAction= new GotoPackageAction(fPart);
+ fGotoResourceAction= new GotoResourceAction(fPart);
+ fCollapseAllAction= new CollapseAllAction(fPart);
+ fToggleLinkingAction = new ToggleLinkingAction(fPart);
+// fGotoRequiredProjectAction= new GotoRequiredProjectAction(fPart);
+ }
+
+ public void dispose() {
+ super.dispose();
+ }
+
+
+ //---- Persistent state -----------------------------------------------------------------------
+
+ /* package */ void restoreFilterAndSorterState(IMemento memento) {
+ fViewActionGroup.restoreState(memento);
+ fCustomFiltersActionGroup.restoreState(memento);
+ }
+
+ /* package */ void saveFilterAndSorterState(IMemento memento) {
+ fViewActionGroup.saveState(memento);
+ fCustomFiltersActionGroup.saveState(memento);
+ }
+
+ //---- Action Bars ----------------------------------------------------------------------------
+
+ public void fillActionBars(IActionBars actionBars) {
+ super.fillActionBars(actionBars);
+ setGlobalActionHandlers(actionBars);
+ fillToolBar(actionBars.getToolBarManager());
+ fillViewMenu(actionBars.getMenuManager());
+ }
+
+ /* package */ void updateActionBars(IActionBars actionBars) {
+ actionBars.getToolBarManager().removeAll();
+ actionBars.getMenuManager().removeAll();
+ fillActionBars(actionBars);
+ actionBars.updateActionBars();
+ fZoomInAction.setEnabled(true);
+ }
+
+ private void setGlobalActionHandlers(IActionBars actionBars) {
+ // Navigate Go Into and Go To actions.
+ actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_INTO, fZoomInAction);
+ actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), fBackAction);
+ actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), fForwardAction);
+ actionBars.setGlobalActionHandler(IWorkbenchActionConstants.UP, fUpAction);
+ actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_TO_RESOURCE, fGotoResourceAction);
+// actionBars.setGlobalActionHandler(RdtActionConstants.GOTO_TYPE, fGotoTypeAction);
+// actionBars.setGlobalActionHandler(RdtActionConstants.GOTO_PACKAGE, fGotoPackageAction);
+
+// fRefactorActionGroup.retargetFileMenuActions(actionBars);
+ }
+
+ /* package */ void fillToolBar(IToolBarManager toolBar) {
+ toolBar.add(fBackAction);
+ toolBar.add(fForwardAction);
+ toolBar.add(fUpAction);
+
+ toolBar.add(new Separator());
+ toolBar.add(fCollapseAllAction);
+ toolBar.add(fToggleLinkingAction);
+
+ }
+
+ /* package */ void fillViewMenu(IMenuManager menu) {
+ menu.add(fToggleLinkingAction);
+
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+"-end"));//$NON-NLS-1$
+ }
+
+ //---- Context menu -------------------------------------------------------------------------
+
+ public void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection= (IStructuredSelection)getContext().getSelection();
+ int size= selection.size();
+ Object element= selection.getFirstElement();
+
+ if (element instanceof LoadPathContainer.RequiredProjectWrapper)
+ menu.appendToGroup(IContextMenuConstants.GROUP_SHOW, fGotoRequiredProjectAction);
+
+ addGotoMenu(menu, element, size);
+
+ addOpenNewWindowAction(menu, element);
+
+ super.fillContextMenu(menu);
+ }
+
+ private void addGotoMenu(IMenuManager menu, Object element, int size) {
+ boolean enabled= size == 1 && fPart.getViewer().isExpandable(element) && (isGoIntoTarget(element) || element instanceof IContainer);
+ fZoomInAction.setEnabled(enabled);
+ if (enabled)
+ menu.appendToGroup(IContextMenuConstants.GROUP_GOTO, fZoomInAction);
+ }
+
+ private boolean isGoIntoTarget(Object element) {
+ if (element == null)
+ return false;
+ if (element instanceof IRubyElement) {
+ int type= ((IRubyElement)element).getElementType();
+ return type == IRubyElement.RUBY_PROJECT ||
+ type == IRubyElement.SOURCE_FOLDER_ROOT ||
+ type == IRubyElement.SOURCE_FOLDER;
+ }
+ if (element instanceof IWorkingSet) {
+ return true;
+ }
+ return false;
+ }
+
+ private void addOpenNewWindowAction(IMenuManager menu, Object element) {
+ if (element instanceof IRubyElement) {
+ element= ((IRubyElement)element).getResource();
+
+ }
+ // fix for 64890 Package explorer out of sync when open/closing projects [package explorer] 64890
+ if (element instanceof IProject && !((IProject)element).isOpen())
+ return;
+
+ if (!(element instanceof IContainer))
+ return;
+ menu.appendToGroup(
+ IContextMenuConstants.GROUP_OPEN,
+ new OpenInNewWindowAction(fPart.getSite().getWorkbenchWindow(), (IContainer)element));
+ }
+
+ //---- Key board and mouse handling ------------------------------------------------------------
+
+ /* package*/ void handleDoubleClick(DoubleClickEvent event) {
+ TreeViewer viewer= fPart.getViewer();
+ IStructuredSelection selection= (IStructuredSelection)event.getSelection();
+ Object element= selection.getFirstElement();
+ if (viewer.isExpandable(element)) {
+ if (doubleClickGoesInto()) {
+ // don't zoom into ruby scripts
+ if (element instanceof IRubyScript)
+ return;
+ if (element instanceof IOpenable || element instanceof IContainer || element instanceof IWorkingSet) {
+ fZoomInAction.run();
+ }
+ } else {
+ IAction openAction= fNavigateActionGroup.getOpenAction();
+ if (openAction != null && openAction.isEnabled() && OpenStrategy.getOpenMethod() == OpenStrategy.DOUBLE_CLICK)
+ return;
+ if (selection instanceof ITreeSelection) {
+ TreePath[] paths= ((ITreeSelection)selection).getPathsFor(element);
+ for (int i= 0; i < paths.length; i++) {
+ viewer.setExpandedState(paths[i], !viewer.getExpandedState(paths[i]));
+ }
+ } else {
+ viewer.setExpandedState(element, !viewer.getExpandedState(element));
+ }
+ }
+ }
+ }
+
+ /* package */ void handleOpen(OpenEvent event) {
+ IAction openAction= fNavigateActionGroup.getOpenAction();
+ if (openAction != null && openAction.isEnabled()) {
+ openAction.run();
+ return;
+ }
+ }
+
+ /* package */ void handleKeyEvent(KeyEvent event) {
+ if (event.stateMask != 0)
+ return;
+
+ if (event.keyCode == SWT.BS) {
+ if (fUpAction != null && fUpAction.isEnabled()) {
+ fUpAction.run();
+ event.doit= false;
+ }
+ }
+ }
+
+ private void doWorkingSetChanged(PropertyChangeEvent event) {
+ if (ViewActionGroup.MODE_CHANGED.equals(event.getProperty())) {
+ fPart.rootModeChanged(((Integer)event.getNewValue()).intValue());
+ Object oldInput= null;
+ Object newInput= null;
+ if (fPart.showProjects()) {
+ oldInput= fPart.getWorkingSetModel();
+ newInput= RubyCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ } else if (fPart.showWorkingSets()) {
+ oldInput= RubyCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ newInput= fPart.getWorkingSetModel();
+ }
+ if (oldInput != null && newInput != null) {
+ Frame frame;
+ for (int i= 0; (frame= fFrameList.getFrame(i)) != null; i++) {
+ if (frame instanceof TreeFrame) {
+ TreeFrame treeFrame= (TreeFrame)frame;
+ if (oldInput.equals(treeFrame.getInput()))
+ treeFrame.setInput(newInput);
+ }
+ }
+ }
+ } else {
+ IWorkingSet workingSet= (IWorkingSet) event.getNewValue();
+
+ String workingSetLabel= null;
+ if (workingSet != null)
+ workingSetLabel= workingSet.getLabel();
+ fPart.setWorkingSetLabel(workingSetLabel);
+ fPart.updateTitle();
+
+ String property= event.getProperty();
+ if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property)) {
+ TreeViewer viewer= fPart.getViewer();
+ viewer.getControl().setRedraw(false);
+ viewer.refresh();
+ viewer.getControl().setRedraw(true);
+ }
+ }
+ }
+
+ private boolean doubleClickGoesInto() {
+ return true;
+// return PreferenceConstants.DOUBLE_CLICK_GOES_INTO.equals(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.DOUBLE_CLICK));
+ }
+
+ public FrameAction getUpAction() {
+ return fUpAction;
+ }
+
+ public FrameAction getBackAction() {
+ return fBackAction;
+ }
+ public FrameAction getForwardAction() {
+ return fForwardAction;
+ }
+
+ public ViewActionGroup getWorkingSetActionGroup() {
+ return fViewActionGroup;
+ }
+
+ public CustomFiltersActionGroup getCustomFilterActionGroup() {
+ return fCustomFiltersActionGroup;
+ }
+
+ public FrameList getFrameList() {
+ return fFrameList;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerActionGroup.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerContentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerContentProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerContentProvider.java 2007-09-07 13:46:11 UTC (rev 3100)
@@ -0,0 +1,695 @@
+/*******************************************************************************
+ * 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.packageview;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.IBasicPropertyConstants;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkingSet;
+import org.rubypeople.rdt.core.ElementChangedEvent;
+import org.rubypeople.rdt.core.IElementChangedListener;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyElementDelta;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.workingsets.WorkingSetModel;
+import org.rubypeople.rdt.ui.StandardRubyElementContentProvider;
+
+/**
+ * Content provider for the PackageExplorer.
+ *
+ * <p>
+ * Since 2.1 this content provider can provide the children for flat or hierarchical
+ * layout. The hierarchical layout is done by delegating to the <code>SourceFolderProvider</code>.
+ * </p>
+ *
+ * @see org.eclipse.jdt.ui.StandardRubyElementContentProvider
+ * @see org.eclipse.jdt.internal.ui.packageview.SourceFolderProvider
+ */
+public class PackageExplorerContentProvider extends StandardRubyElementContentProvider implements ITreeContentProvider, IElementChangedListener {
+
+ protected static final int ORIGINAL= 0;
+ protected static final int PARENT= 1 << 0;
+ protected static final int GRANT_PARENT= 1 << 1;
+ protected static final int PROJECT= 1 << 2;
+
+ private TreeViewer fViewer;
+ private Object fInput;
+ private boolean fIsFlatLayout;
+ private SourceFolderProvider fSourceFolderProvider;
+
+ private int fPendingChanges;
+
+ /**
+ * Creates a new content provider for Ruby elements.
+ */
+ public PackageExplorerContentProvider(boolean provideMembers) {
+ super(provideMembers);
+ fSourceFolderProvider= new SourceFolderProvider();
+ }
+
+ /* package */ SourceFolderProvider getSourceFolderProvider() {
+ return fSourceFolderProvider;
+ }
+
+ protected Object getViewerInput() {
+ return fInput;
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on IElementChangedListener.
+ */
+ public void elementChanged(final ElementChangedEvent event) {
+ try {
+ // 58952 delete project does not update Package Explorer [package explorer]
+ // if the input to the viewer is deleted then refresh to avoid the display of stale elements
+ if (inputDeleted())
+ return;
+ processDelta(event.getDelta());
+ } catch(RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+ }
+
+ private boolean inputDeleted() {
+ if (fInput == null)
+ return false;
+ if ((fInput instanceof IRubyElement) && ((IRubyElement) fInput).exists())
+ return false;
+ if ((fInput instanceof IResource) && ((IResource) fInput).exists())
+ return false;
+ if (fInput instanceof WorkingSetModel)
+ return false;
+ if (fInput instanceof IWorkingSet) // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156239
+ return false;
+ postRefresh(fInput, ORIGINAL, fInput);
+ return true;
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on IContentProvider.
+ */
+ public void dispose() {
+ super.dispose();
+ RubyCore.removeElementChangedListener(this);
+ fSourceFolderProvider.dispose();
+ }
+
+ // ------ Code which delegates to SourceFolderProvider ------
+
+ private boolean needsToDelegateGetChildren(Object element) {
+ int type= -1;
+ if (element instanceof IRubyElement)
+ type= ((IRubyElement)element).getElementType();
+ return (!fIsFlatLayout && (type == IRubyElement.SOURCE_FOLDER || type == IRubyElement.SOURCE_FOLDER_ROOT || type == IRubyElement.RUBY_PROJECT || element instanceof IFolder));
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ Object[] children= NO_CHILDREN;
+ try {
+ if (parentElement instanceof IRubyModel)
+ return concatenate(getRubyProjects((IRubyModel)parentElement), getNonRubyProjects((IRubyModel)parentElement));
+
+ if (parentElement instanceof LoadPathContainer)
+ return getContainerSourceFolderRoots((LoadPathContainer)parentElement);
+
+ if (parentElement instanceof IProject)
+ return ((IProject)parentElement).members();
+
+ if (needsToDelegateGetChildren(parentElement)) {
+ Object[] packageFragments= fSourceFolderProvider.getChildren(parentElement);
+ children= getWithParentsResources(packageFragments, parentElement);
+ } else {
+ children= super.getChildren(parentElement);
+ }
+
+ if (parentElement instanceof IRubyProject) {
+ IRubyProject project= (IRubyProject)parentElement;
+ return rootsAndContainers(project, children);
+ }
+ else
+ return children;
+
+ } catch (CoreException e) {
+ return NO_CHILDREN;
+ }
+ }
+
+ private Object[] rootsAndContainers(IRubyProject project, Object[] roots) throws RubyModelException {
+ List result= new ArrayList(roots.length);
+ Set containers= new HashSet(roots.length);
+ Set containedRoots= new HashSet(roots.length);
+
+ ILoadpathEntry[] entries= project.getRawLoadpath();
+ for (int i= 0; i < entries.length; i++) {
+ ILoadpathEntry entry= entries[i];
+ if (entry != null && entry.getEntryKind() == ILoadpathEntry.CPE_CONTAINER) {
+ ISourceFolderRoot[] roots1= project.findSourceFolderRoots(entry);
+ containedRoots.addAll(Arrays.asList(roots1));
+ containers.add(entry);
+ }
+ }
+ for (int i= 0; i < roots.length; i++) {
+ if (roots[i] instanceof ISourceFolderRoot) {
+ if (!containedRoots.contains(roots[i])) {
+ result.add(roots[i]);
+ }
+ } else {
+ result.add(roots[i]);
+ }
+ }
+ for (Iterator each= containers.iterator(); each.hasNext();) {
+ ILoadpathEntry element= (ILoadpathEntry) each.next();
+ result.add(new LoadPathContainer(project, element));
+ }
+ return result.toArray();
+ }
+
+ private Object[] getContainerSourceFolderRoots(LoadPathContainer container) {
+ return container.getChildren(container);
+ }
+
+ private Object[] getNonRubyProjects(IRubyModel model) throws RubyModelException {
+ return model.getNonRubyResources();
+ }
+
+ public Object getParent(Object child) {
+ if (needsToDelegateGetParent(child)) {
+ return fSourceFolderProvider.getParent(child);
+ } else
+ return super.getParent(child);
+ }
+
+ protected Object internalGetParent(Object element) {
+ // since we insert logical package containers we have to fix
+ // up the parent for package fragment roots so that they refer
+ // to the container and containers refere to the project
+ //
+ if (element instanceof ISourceFolderRoot) {
+ ISourceFolderRoot root= (ISourceFolderRoot)element;
+ IRubyProject project= root.getRubyProject();
+ try {
+ ILoadpathEntry[] entries= project.getRawLoadpath();
+ for (int i= 0; i < entries.length; i++) {
+ ILoadpathEntry entry= entries[i];
+ if (entry.getEntryKind() == ILoadpathEntry.CPE_CONTAINER) {
+ if (LoadPathContainer.contains(project, entry, root))
+ return new LoadPathContainer(project, entry);
+ }
+ }
+ } catch (RubyModelException e) {
+ // fall through
+ }
+ }
+ if (element instanceof LoadPathContainer) {
+ return ((LoadPathContainer)element).getRubyProject();
+ }
+ return super.internalGetParent(element);
+ }
+
+ private boolean needsToDelegateGetParent(Object element) {
+ int type= -1;
+ if (element instanceof IRubyElement)
+ type= ((IRubyElement)element).getElementType();
+ return (!fIsFlatLayout && type == IRubyElement.SOURCE_FOLDER);
+ }
+
+ /**
+ * Returns the given objects with the resources of the parent.
+ */
+ private Object[] getWithParentsResources(Object[] existingObject, Object parent) {
+ Object[] objects= super.getChildren(parent);
+ List list= new ArrayList();
+
+ // Add everything that is not a SourceFolder (Files)
+ for (int i= 0; i < objects.length; i++) {
+ Object object= objects[i];
+ if (!(object instanceof ISourceFolder)) {
+ list.add(object);
+ }
+ }
+ if (existingObject != null)
+ list.addAll(Arrays.asList(existingObject));
+
+ return list.toArray();
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on IContentProvider.
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ super.inputChanged(viewer, oldInput, newInput);
+ fSourceFolderProvider.inputChanged(viewer, oldInput, newInput);
+ fViewer= (TreeViewer)viewer;
+ if (oldInput == null && newInput != null) {
+ RubyCore.addElementChangedListener(this);
+ } else if (oldInput != null && newInput == null) {
+ RubyCore.removeElementChangedListener(this);
+ }
+ fInput= newInput;
+ }
+
+ // ------ delta processing ------
+
+ /**
+ * Processes a delta recursively. When more than two children are affected the
+ * tree is fully refreshed starting at this node. The delta is processed in the
+ * current thread but the viewer updates are posted to the UI thread.
+ */
+ private void processDelta(IRubyElementDelta delta) throws RubyModelException {
+
+ int kind= delta.getKind();
+ int flags= delta.getFlags();
+ IRubyElement element= delta.getElement();
+ int elementType= element.getElementType();
+
+
+ if (elementType != IRubyElement.RUBY_MODEL && elementType != IRubyElement.RUBY_PROJECT) {
+ IRubyProject proj= element.getRubyProject();
+ if (proj == null || !proj.getProject().isOpen()) // TODO: Not needed if parent already did the 'open' check!
+ return;
+ }
+
+ if (!fIsFlatLayout && elementType == IRubyElement.SOURCE_FOLDER) {
+ fSourceFolderProvider.processDelta(delta);
+ if (processResourceDeltas(delta.getResourceDeltas(), element))
+ return;
+ handleAffectedChildren(delta, element);
+ return;
+ }
+
+ if (elementType == IRubyElement.SCRIPT) {
+ IRubyScript cu= (IRubyScript) element;
+ if (!RubyModelUtil.isPrimary(cu)) {
+ return;
+ }
+
+ if (!getProv...
[truncated message content] |