|
From: <caw...@us...> - 2006-12-06 15:31:30
|
Revision: 1679
http://svn.sourceforge.net/rubyeclipse/?rev=1679&view=rev
Author: cawilliams
Date: 2006-12-06 07:31:27 -0800 (Wed, 06 Dec 2006)
Log Message:
-----------
a new RDT merge/compare feature (based off of Mirko's patch and the JDT's implementation). We now do coloring of syntax in the diff view for checking in/out.
Next logical step would be to create a structure view and structure diff (so we can compare high-level changes like adding/removing methods)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/EclipsePreferencesAdapter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyCompareUtilities.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewCreator.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewer.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyNode.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewer.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewerCreator.java
Modified: trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2006-12-06 15:01:06 UTC (rev 1678)
+++ trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2006-12-06 15:31:27 UTC (rev 1679)
@@ -50,5 +50,6 @@
org.eclipse.ui.forms,
org.rubypeople.rdt.launching,
org.eclipse.search,
- org.jruby
+ org.jruby,
+ org.eclipse.compare
Eclipse-LazyStart: true
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-06 15:01:06 UTC (rev 1678)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-06 15:31:27 UTC (rev 1679)
@@ -6,7 +6,7 @@
<extension-point id="foldingStructureProviders" name="%foldingStructureProviders" schema="schema/foldingStructureProviders.exsd"/>
<extension-point id="editorPopupExtender" name="%editorPopupExtender" schema="schema/org.rubypeople.rdt.ui.editorPopupExtender.exsd"/>
<extension-point id="rubyTemplateProvider" name="Ruby template provider" schema="schema/rubyTemplateProvider.exsd"/>
-
+
<extension
point="org.eclipse.ui.preferencePages">
<page
@@ -919,5 +919,26 @@
</description>
</fontDefinition>
</extension>
-
+
+ <extension
+ point="org.eclipse.compare.contentViewers">
+ <viewer
+ class="org.rubypeople.rdt.internal.ui.compare.RubyTextViewerCreator"
+ id="org.rubypeople.rdt.internal.ui.compare.RubyTextViewerCreator">
+ </viewer>
+ <contentTypeBinding
+ contentTypeId="org.rubypeople.rdt.core.rubySource"
+ contentViewerId="org.rubypeoplee.rdt.internal.ui.compare.RubyTextViewerCreator">
+ </contentTypeBinding>
+ </extension>
+ <extension
+ point="org.eclipse.compare.contentMergeViewers">
+ <viewer
+ class="org.rubypeople.rdt.internal.ui.compare.RubyMergeViewCreator"
+ id="org.rubypeople.rdt.internal.ui.RubyMergeViewer"/>
+ <contentTypeBinding
+ contentMergeViewerId="org.rubypeople.rdt.internal.ui.RubyMergeViewer"
+ contentTypeId="org.rubypeople.rdt.core.rubySource"/>
+ </extension>
+
</plugin>
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java 2006-12-06 15:01:06 UTC (rev 1678)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -3,12 +3,14 @@
import java.net.MalformedURLException;
import java.net.URL;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
+import org.osgi.framework.Bundle;
public class RubyPluginImages {
@@ -230,4 +232,22 @@
buffer.append(name);
return new URL(iconBaseURL, buffer.toString());
}
+
+ /*
+ * Creates an image descriptor for the given path in a bundle. The path can contain variables
+ * like $NL$.
+ * If no image could be found, <code>useMissingImageDescriptor</code> decides if either
+ * the 'missing image descriptor' is returned or <code>null</code>.
+ * Added for 3.1.1.
+ */
+ public static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path, boolean useMissingImageDescriptor) {
+ URL url= FileLocator.find(bundle, path, null);
+ if (url != null) {
+ return ImageDescriptor.createFromURL(url);
+ }
+ if (useMissingImageDescriptor) {
+ return ImageDescriptor.getMissingImageDescriptor();
+ }
+ return null;
+ }
}
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,19 @@
+package org.rubypeople.rdt.internal.ui.compare;
+
+import org.eclipse.osgi.util.NLS;
+
+public class CompareMessages extends NLS {
+ private static final String BUNDLE_NAME= "org.rubypeople.rdt.internal.ui.compare.CompareMessages";//$NON-NLS-1$
+
+ private CompareMessages() {
+ // Do not instantiate
+ }
+
+ public static String RubyNode_importDeclarations;
+ public static String RubyNode_script;
+ public static String RubyMergeViewer_title;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.properties (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/CompareMessages.properties 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,19 @@
+###############################################################################
+# 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
+###############################################################################
+
+
+#
+# Title of Ruby source compare viewer
+#
+RubyMergeViewer_title= Ruby Source Compare
+
+RubyNode_script= Ruby Script
+RubyNode_importDeclarations= Import Declarations
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/EclipsePreferencesAdapter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/EclipsePreferencesAdapter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/EclipsePreferencesAdapter.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,319 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 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.compare;
+
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.widgets.Display;
+import org.osgi.service.prefs.BackingStoreException;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * Adapts an options {@link IEclipsePreferences} to {@link org.eclipse.jface.preference.IPreferenceStore}.
+ * <p>
+ * This preference store is read-only i.e. write access
+ * throws an {@link java.lang.UnsupportedOperationException}.
+ * </p>
+ *
+ * @since 3.1
+ */
+class EclipsePreferencesAdapter implements IPreferenceStore {
+
+ /**
+ * Preference change listener. Listens for events preferences
+ * fires a {@link org.eclipse.jface.util.PropertyChangeEvent}
+ * on this adapter with arguments from the received event.
+ */
+ private class PreferenceChangeListener implements IEclipsePreferences.IPreferenceChangeListener {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void preferenceChange(final IEclipsePreferences.PreferenceChangeEvent event) {
+ if (Display.getCurrent() == null) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ firePropertyChangeEvent(event.getKey(), event.getOldValue(), event.getNewValue());
+ }
+ });
+ } else {
+ firePropertyChangeEvent(event.getKey(), event.getOldValue(), event.getNewValue());
+ }
+ }
+ }
+
+ /** Listeners on on this adapter */
+ private ListenerList fListeners= new ListenerList(ListenerList.IDENTITY);
+
+ /** Listener on the node */
+ private IEclipsePreferences.IPreferenceChangeListener fListener= new PreferenceChangeListener();
+
+ /** wrapped node */
+ private final IScopeContext fContext;
+ private final String fQualifier;
+
+ /**
+ * Initialize with the node to wrap
+ *
+ * @param context The context to access
+ */
+ public EclipsePreferencesAdapter(IScopeContext context, String qualifier) {
+ fContext= context;
+ fQualifier= qualifier;
+ }
+
+ private IEclipsePreferences getNode() {
+ return fContext.getNode(fQualifier);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addPropertyChangeListener(IPropertyChangeListener listener) {
+ if (fListeners.size() == 0)
+ getNode().addPreferenceChangeListener(fListener);
+ fListeners.add(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removePropertyChangeListener(IPropertyChangeListener listener) {
+ fListeners.remove(listener);
+ if (fListeners.size() == 0) {
+ getNode().removePreferenceChangeListener(fListener);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean contains(String name) {
+ return getNode().get(name, null) != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
+ PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue);
+ Object[] listeners= fListeners.getListeners();
+ for (int i= 0; i < listeners.length; i++)
+ ((IPropertyChangeListener) listeners[i]).propertyChange(event);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean getBoolean(String name) {
+ return getNode().getBoolean(name, BOOLEAN_DEFAULT_DEFAULT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean getDefaultBoolean(String name) {
+ return BOOLEAN_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public double getDefaultDouble(String name) {
+ return DOUBLE_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public float getDefaultFloat(String name) {
+ return FLOAT_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDefaultInt(String name) {
+ return INT_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getDefaultLong(String name) {
+ return LONG_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDefaultString(String name) {
+ return STRING_DEFAULT_DEFAULT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public double getDouble(String name) {
+ return getNode().getDouble(name, DOUBLE_DEFAULT_DEFAULT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public float getFloat(String name) {
+ return getNode().getFloat(name, FLOAT_DEFAULT_DEFAULT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getInt(String name) {
+ return getNode().getInt(name, INT_DEFAULT_DEFAULT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getLong(String name) {
+ return getNode().getLong(name, LONG_DEFAULT_DEFAULT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString(String name) {
+ return getNode().get(name, STRING_DEFAULT_DEFAULT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDefault(String name) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean needsSaving() {
+ try {
+ return getNode().keys().length > 0;
+ } catch (BackingStoreException e) {
+ // ignore
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void putValue(String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, String defaultObject) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDefault(String name, boolean value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setToDefault(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValue(String name, boolean value) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyCompareUtilities.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyCompareUtilities.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyCompareUtilities.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,415 @@
+/*******************************************************************************
+ * 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.compare;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.IEncodedStreamContentAccessor;
+import org.eclipse.compare.IStreamContentAccessor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.swt.graphics.Image;
+import org.rubypeople.rdt.core.IMember;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
+import org.rubypeople.rdt.ui.RubyElementLabels;
+import org.rubypeople.rdt.ui.text.RubyTextTools;
+
+class RubyCompareUtilities {
+
+ private static final char IMPORTDECLARATION= '#';
+ private static final char IMPORT_CONTAINER= '<';
+ private static final char FIELD= '^';
+ private static final char METHOD= '~';
+ private static final char SCRIPT= '{';
+ private static final char TYPE= '[';
+
+ static String getString(ResourceBundle bundle, String key, String dfltValue) {
+
+ if (bundle != null) {
+ try {
+ return bundle.getString(key);
+ } catch (MissingResourceException x) {
+ // NeedWork
+ }
+ }
+ return dfltValue;
+ }
+
+ static String getString(ResourceBundle bundle, String key) {
+ return getString(bundle, key, key);
+ }
+
+ static int getInteger(ResourceBundle bundle, String key, int dfltValue) {
+
+ if (bundle != null) {
+ try {
+ String s= bundle.getString(key);
+ if (s != null)
+ return Integer.parseInt(s);
+ } catch (NumberFormatException x) {
+ // NeedWork
+ } catch (MissingResourceException x) {
+ // NeedWork
+ }
+ }
+ return dfltValue;
+ }
+
+ static ImageDescriptor getImageDescriptor(int type) {
+ switch (type) {
+ case IRubyElement.METHOD:
+ return getImageDescriptor("obj16/compare_method.gif"); //$NON-NLS-1$
+ case IRubyElement.FIELD:
+ return getImageDescriptor("obj16/compare_field.gif"); //$NON-NLS-1$
+ case IRubyElement.IMPORT_DECLARATION:
+ return RubyPluginImages.DESC_OBJS_IMPDECL;
+ case IRubyElement.IMPORT_CONTAINER:
+ return RubyPluginImages.DESC_OBJS_IMPCONT;
+ case IRubyElement.SCRIPT:
+ return RubyPluginImages.DESC_OBJS_SCRIPT;
+ }
+ return ImageDescriptor.getMissingImageDescriptor();
+ }
+
+ static ImageDescriptor getTypeImageDescriptor(boolean isClass) {
+ if (isClass)
+ return RubyPluginImages.DESC_OBJS_CLASS;
+ return RubyPluginImages.DESC_OBJS_MODULE;
+ }
+
+ static ImageDescriptor getImageDescriptor(IMember element) {
+ int t= element.getElementType();
+ if (t == IRubyElement.TYPE) {
+ IType type= (IType) element;
+ return getTypeImageDescriptor(type.isClass());
+ }
+ return getImageDescriptor(t);
+ }
+
+ /**
+ * Returns a name for the given Ruby element that uses the same conventions
+ * as the RubyNode name of a corresponding element.
+ */
+ static String getRubyElementID(IRubyElement je) {
+
+ StringBuffer sb= new StringBuffer();
+
+ switch (je.getElementType()) {
+ case IRubyElement.SCRIPT:
+ sb.append(SCRIPT);
+ break;
+ case IRubyElement.TYPE:
+ sb.append(TYPE);
+ sb.append(je.getElementName());
+ break;
+ case IRubyElement.FIELD:
+ sb.append(FIELD);
+ sb.append(je.getElementName());
+ break;
+ case IRubyElement.METHOD:
+ sb.append(METHOD);
+ sb.append(RubyElementLabels.getElementLabel(je, RubyElementLabels.M_PARAMETER_NAMES));
+ break;
+ case IRubyElement.IMPORT_CONTAINER:
+ sb.append(IMPORT_CONTAINER);
+ break;
+ case IRubyElement.IMPORT_DECLARATION:
+ sb.append(IMPORTDECLARATION);
+ sb.append(je.getElementName());
+ break;
+ default:
+ return null;
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns a name which identifies the given typed name.
+ * The type is encoded as a single character at the beginning of the string.
+ */
+ static String buildID(int type, String name) {
+ StringBuffer sb= new StringBuffer();
+ switch (type) {
+ case RubyNode.SCRIPT:
+ sb.append(SCRIPT);
+ break;
+ case RubyNode.CLASS:
+ case RubyNode.MODULE:
+ sb.append(TYPE);
+ sb.append(name);
+ break;
+ case RubyNode.FIELD:
+ sb.append(FIELD);
+ sb.append(name);
+ break;
+ case RubyNode.CONSTRUCTOR:
+ case RubyNode.METHOD:
+ sb.append(METHOD);
+ sb.append(name);
+ break;
+ case RubyNode.IMPORT:
+ sb.append(IMPORTDECLARATION);
+ sb.append(name);
+ break;
+ case RubyNode.IMPORT_CONTAINER:
+ sb.append(IMPORT_CONTAINER);
+ break;
+ default:
+ Assert.isTrue(false);
+ break;
+ }
+ return sb.toString();
+ }
+
+ static ImageDescriptor getImageDescriptor(String relativePath) {
+ IPath path= RubyPluginImages.ICONS_PATH.append(relativePath);
+ return RubyPluginImages.createImageDescriptor(RubyPlugin.getDefault().getBundle(), path, true);
+ }
+
+ static boolean getBoolean(CompareConfiguration cc, String key, boolean dflt) {
+ if (cc != null) {
+ Object value= cc.getProperty(key);
+ if (value instanceof Boolean)
+ return ((Boolean) value).booleanValue();
+ }
+ return dflt;
+ }
+
+ static Image getImage(IMember member) {
+ ImageDescriptor id= getImageDescriptor(member);
+ return id.createImage();
+ }
+
+ static RubyTextTools getRubyTextTools() {
+ RubyPlugin plugin= RubyPlugin.getDefault();
+ if (plugin != null)
+ return plugin.getRubyTextTools();
+ return null;
+ }
+
+ static IDocumentPartitioner createRubyPartitioner() {
+ RubyTextTools tools= getRubyTextTools();
+ if (tools != null)
+ return tools.createDocumentPartitioner();
+ return null;
+ }
+
+ static void setupDocument(IDocument document) {
+ RubyTextTools tools= getRubyTextTools();
+ if (tools != null)
+ tools.setupRubyDocumentPartitioner(document, IRubyPartitions.RUBY_PARTITIONING);
+ }
+
+ /**
+ * Reads the contents of the given input stream into a string.
+ * The function assumes that the input stream uses the platform's default encoding
+ * (<code>ResourcesPlugin.getEncoding()</code>).
+ * Returns null if an error occurred.
+ */
+ private static String readString(InputStream is, String encoding) {
+ if (is == null)
+ return null;
+ BufferedReader reader= null;
+ try {
+ StringBuffer buffer= new StringBuffer();
+ char[] part= new char[2048];
+ int read= 0;
+ reader= new BufferedReader(new InputStreamReader(is, encoding));
+
+ while ((read= reader.read(part)) != -1)
+ buffer.append(part, 0, read);
+
+ return buffer.toString();
+
+ } catch (IOException ex) {
+ // NeedWork
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException ex) {
+ // silently ignored
+ }
+ }
+ }
+ return null;
+ }
+
+ public static String readString(IStreamContentAccessor sa) throws CoreException {
+ InputStream is= sa.getContents();
+ if (is != null) {
+ String encoding= null;
+ if (sa instanceof IEncodedStreamContentAccessor) {
+ try {
+ encoding= ((IEncodedStreamContentAccessor) sa).getCharset();
+ } catch (Exception e) {
+ }
+ }
+ if (encoding == null)
+ encoding= ResourcesPlugin.getEncoding();
+ return readString(is, encoding);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the contents of the given string as an array of bytes
+ * in the platform's default encoding.
+ */
+ static byte[] getBytes(String s, String encoding) {
+ try {
+ return s.getBytes(encoding);
+ } catch (UnsupportedEncodingException e) {
+ return s.getBytes();
+ }
+ }
+
+ /**
+ * Breaks the contents of the given input stream into an array of strings.
+ * The function assumes that the input stream uses the platform's default encoding
+ * (<code>ResourcesPlugin.getEncoding()</code>).
+ * Returns null if an error occurred.
+ */
+ static String[] readLines(InputStream is2, String encoding) {
+
+ BufferedReader reader= null;
+ try {
+ reader= new BufferedReader(new InputStreamReader(is2, encoding));
+ StringBuffer sb= new StringBuffer();
+ List list= new ArrayList();
+ while (true) {
+ int c= reader.read();
+ if (c == -1)
+ break;
+ sb.append((char)c);
+ if (c == '\r') { // single CR or a CR followed by LF
+ c= reader.read();
+ if (c == -1)
+ break;
+ sb.append((char)c);
+ if (c == '\n') {
+ list.add(sb.toString());
+ sb= new StringBuffer();
+ }
+ } else if (c == '\n') { // a single LF
+ list.add(sb.toString());
+ sb= new StringBuffer();
+ }
+ }
+ if (sb.length() > 0)
+ list.add(sb.toString());
+ return (String[]) list.toArray(new String[list.size()]);
+
+ } catch (IOException ex) {
+ return null;
+
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException ex) {
+ // silently ignored
+ }
+ }
+ }
+ }
+
+ /*
+ * Initialize the given Action from a ResourceBundle.
+ */
+ static void initAction(IAction a, ResourceBundle bundle, String prefix) {
+
+ String labelKey= "label"; //$NON-NLS-1$
+ String tooltipKey= "tooltip"; //$NON-NLS-1$
+ String imageKey= "image"; //$NON-NLS-1$
+ String descriptionKey= "description"; //$NON-NLS-1$
+
+ if (prefix != null && prefix.length() > 0) {
+ labelKey= prefix + labelKey;
+ tooltipKey= prefix + tooltipKey;
+ imageKey= prefix + imageKey;
+ descriptionKey= prefix + descriptionKey;
+ }
+
+ a.setText(getString(bundle, labelKey, labelKey));
+ a.setToolTipText(getString(bundle, tooltipKey, null));
+ a.setDescription(getString(bundle, descriptionKey, null));
+
+ String relPath= getString(bundle, imageKey, null);
+ if (relPath != null && relPath.trim().length() > 0) {
+
+ String dPath;
+ String ePath;
+
+ if (relPath.indexOf("/") >= 0) { //$NON-NLS-1$
+ String path= relPath.substring(1);
+ dPath= 'd' + path;
+ ePath= 'e' + path;
+ } else {
+ dPath= "dlcl16/" + relPath; //$NON-NLS-1$
+ ePath= "elcl16/" + relPath; //$NON-NLS-1$
+ }
+
+ ImageDescriptor id= RubyCompareUtilities.getImageDescriptor(dPath); // we set the disabled image first (see PR 1GDDE87)
+ if (id != null)
+ a.setDisabledImageDescriptor(id);
+ id= RubyCompareUtilities.getImageDescriptor(ePath);
+ if (id != null) {
+ a.setImageDescriptor(id);
+ a.setHoverImageDescriptor(id);
+ }
+ }
+ }
+
+ static void initToggleAction(IAction a, ResourceBundle bundle, String prefix, boolean checked) {
+
+ String tooltip= null;
+ if (checked)
+ tooltip= getString(bundle, prefix + "tooltip.checked", null); //$NON-NLS-1$
+ else
+ tooltip= getString(bundle, prefix + "tooltip.unchecked", null); //$NON-NLS-1$
+ if (tooltip == null)
+ tooltip= getString(bundle, prefix + "tooltip", null); //$NON-NLS-1$
+
+ if (tooltip != null)
+ a.setToolTipText(tooltip);
+
+ String description= null;
+ if (checked)
+ description= getString(bundle, prefix + "description.checked", null); //$NON-NLS-1$
+ else
+ description= getString(bundle, prefix + "description.unchecked", null); //$NON-NLS-1$
+ if (description == null)
+ description= getString(bundle, prefix + "description", null); //$NON-NLS-1$
+
+ if (description != null)
+ a.setDescription(description);
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewCreator.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewCreator.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewCreator.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,16 @@
+package org.rubypeople.rdt.internal.ui.compare;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.IViewerCreator;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+
+public class RubyMergeViewCreator implements IViewerCreator {
+
+ public Viewer createViewer(Composite parent, CompareConfiguration config) {
+ return new RubyMergeViewer(parent, SWT.NULL, config);
+ }
+
+}
+
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewer.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyMergeViewer.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,248 @@
+package org.rubypeople.rdt.internal.ui.compare;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.IResourceProvider;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
+import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.ui.texteditor.ChainedPreferenceStore;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.text.IRubyColorConstants;
+import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
+import org.rubypeople.rdt.internal.ui.text.PreferencesAdapter;
+import org.rubypeople.rdt.ui.text.RubySourceViewerConfiguration;
+import org.rubypeople.rdt.ui.text.RubyTextTools;
+
+public class RubyMergeViewer extends TextMergeViewer {
+
+ private IPropertyChangeListener fPreferenceChangeListener;
+ private IPreferenceStore fPreferenceStore;
+ private boolean fUseSystemColors;
+ private RubySourceViewerConfiguration fSourceViewerConfiguration;
+ private ArrayList fSourceViewer;
+
+ public RubyMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
+ super(parent, styles | SWT.LEFT_TO_RIGHT, mp);
+
+ getPreferenceStore();
+
+ fUseSystemColors= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
+ if (! fUseSystemColors) {
+ RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
+ setBackgroundColor(bg);
+ RGB fg= createColor(fPreferenceStore, IRubyColorConstants.RUBY_DEFAULT);
+ setForegroundColor(fg);
+ }
+ }
+
+ @Override
+ protected IDocumentPartitioner getDocumentPartitioner() {
+ return RubyPlugin.getDefault().getRubyTextTools().createDocumentPartitioner();
+ }
+
+ @Override
+ protected String getDocumentPartitioning() {
+ return IRubyPartitions.RUBY_PARTITIONING;
+ }
+
+ @Override
+ public void setInput(Object input) {
+ if (input instanceof ICompareInput) {
+ IRubyProject project= getRubyProject((ICompareInput)input);
+ if (project != null) {
+ setPreferenceStore(createChainedPreferenceStore(project));
+ if (fSourceViewer != null) {
+ Iterator iterator= fSourceViewer.iterator();
+ while (iterator.hasNext()) {
+ SourceViewer sourceViewer= (SourceViewer) iterator.next();
+ sourceViewer.unconfigure();
+ sourceViewer.configure(getSourceViewerConfiguration());
+ }
+ }
+ }
+ }
+
+ super.setInput(input);
+ }
+
+ public String getTitle() {
+ return CompareMessages.RubyMergeViewer_title;
+ }
+
+ public IRubyProject getRubyProject(ICompareInput input) {
+
+ if (input == null)
+ return null;
+
+ IResourceProvider rp= null;
+ ITypedElement te= input.getLeft();
+ if (te instanceof IResourceProvider)
+ rp= (IResourceProvider) te;
+ if (rp == null) {
+ te= input.getRight();
+ if (te instanceof IResourceProvider)
+ rp= (IResourceProvider) te;
+ }
+ if (rp == null) {
+ te= input.getAncestor();
+ if (te instanceof IResourceProvider)
+ rp= (IResourceProvider) te;
+ }
+ if (rp != null) {
+ IResource resource= rp.getResource();
+ if (resource != null) {
+ IRubyElement element= RubyCore.create(resource);
+ if (element != null)
+ return element.getRubyProject();
+ }
+ }
+ return null;
+ }
+
+ private ChainedPreferenceStore createChainedPreferenceStore(IRubyProject project) {
+ ArrayList stores= new ArrayList(4);
+ if (project != null)
+ stores.add(new EclipsePreferencesAdapter(new ProjectScope(project.getProject()), RubyCore.PLUGIN_ID));
+ stores.add(RubyPlugin.getDefault().getPreferenceStore());
+ stores.add(new PreferencesAdapter(RubyCore.getPlugin().getPluginPreferences()));
+ stores.add(EditorsUI.getPreferenceStore());
+ return new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
+ }
+
+ private RubySourceViewerConfiguration getSourceViewerConfiguration() {
+ if (fSourceViewerConfiguration == null)
+ getPreferenceStore();
+ return fSourceViewerConfiguration;
+ }
+
+ private IPreferenceStore getPreferenceStore() {
+ if (fPreferenceStore == null)
+ setPreferenceStore(createChainedPreferenceStore(null));
+ return fPreferenceStore;
+ }
+
+ private void setPreferenceStore(IPreferenceStore ps) {
+ if (fPreferenceChangeListener != null) {
+ if (fPreferenceStore != null)
+ fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
+ fPreferenceChangeListener= null;
+ }
+ fPreferenceStore= ps;
+ if (fPreferenceStore != null) {
+ RubyTextTools tools= RubyCompareUtilities.getRubyTextTools();
+ fSourceViewerConfiguration= new RubySourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, getDocumentPartitioning());
+ fPreferenceChangeListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ handlePropertyChange(event);
+ }
+ };
+ fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
+ }
+ }
+
+ private void handlePropertyChange(PropertyChangeEvent event) {
+
+ String key= event.getProperty();
+
+ if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)) {
+
+ if (!fUseSystemColors) {
+ RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
+ setBackgroundColor(bg);
+ }
+
+ } else if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
+
+ fUseSystemColors= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
+ if (fUseSystemColors) {
+ setBackgroundColor(null);
+ setForegroundColor(null);
+ } else {
+ RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
+ setBackgroundColor(bg);
+ RGB fg= createColor(fPreferenceStore, IRubyColorConstants.RUBY_DEFAULT);
+ setForegroundColor(fg);
+ }
+ } else if (key.equals(IRubyColorConstants.RUBY_DEFAULT)) {
+
+ if (!fUseSystemColors) {
+ RGB fg= createColor(fPreferenceStore, IRubyColorConstants.RUBY_DEFAULT);
+ setForegroundColor(fg);
+ }
+ }
+
+ if (fSourceViewerConfiguration != null && fSourceViewerConfiguration.affectsTextPresentation(event)) {
+ fSourceViewerConfiguration.handlePropertyChangeEvent(event);
+ invalidateTextPresentation();
+ }
+ }
+
+ /**
+ * Creates a color from the information stored in the given preference store.
+ * Returns <code>null</code> if there is no such information available.
+ */
+ private static RGB createColor(IPreferenceStore store, String key) {
+ if (!store.contains(key))
+ return null;
+ if (store.isDefault(key))
+ return PreferenceConverter.getDefaultColor(store, key);
+ return PreferenceConverter.getColor(store, key);
+ }
+
+ @Override
+ protected void configureTextViewer(TextViewer textViewer) {
+ if (textViewer instanceof SourceViewer) {
+ if (fSourceViewer == null)
+ fSourceViewer= new ArrayList();
+ fSourceViewer.add(textViewer);
+ RubyTextTools tools= RubyCompareUtilities.getRubyTextTools();
+ if (tools != null)
+ ((SourceViewer)textViewer).configure(getSourceViewerConfiguration());
+ }
+// if (textViewer instanceof SourceViewer) {
+//
+// SourceViewer sourceViewer = ((SourceViewer) textViewer);
+//
+// RubyTextTools tools = RubyPlugin.getDefault().getRubyTextTools();
+// Document doc = new Document();
+// tools.setupRubyDocumentPartitioner(doc, IRubyPartitions.RUBY_PARTITIONING);
+//
+// IPreferenceStore[] chain = { RubyPlugin.getDefault().getCombinedPreferenceStore() };
+// ChainedPreferenceStore preferenceStore = new ChainedPreferenceStore(chain);
+//
+// SimpleRubySourceViewerConfiguration viewerConfiguration = new SimpleRubySourceViewerConfiguration(tools
+// .getColorManager(), preferenceStore, null, IRubyPartitions.RUBY_PARTITIONING, true);
+// sourceViewer.configure(viewerConfiguration);
+//
+// } else {
+// super.configureTextViewer(textViewer);
+// }
+ }
+
+ protected void handleDispose(DisposeEvent event) {
+ setPreferenceStore(null);
+ fSourceViewer= null;
+ super.handleDispose(event);
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyNode.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyNode.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyNode.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * 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.compare;
+
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.structuremergeviewer.DocumentRangeNode;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.swt.graphics.Image;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+
+/**
+ * Comparable Ruby elements are represented as RubyNodes.
+ * Extends the DocumentRangeNode with method signature information.
+ */
+class RubyNode extends DocumentRangeNode implements ITypedElement {
+
+ public static final int SCRIPT= 0;
+ public static final int IMPORT_CONTAINER= 2;
+ public static final int IMPORT= 3;
+ public static final int MODULE= 4;
+ public static final int CLASS= 5;
+ public static final int FIELD= 8;
+ public static final int CONSTRUCTOR= 10;
+ public static final int METHOD= 11;
+
+ private int fInitializerCount= 1;
+ private boolean fIsEditable;
+ private RubyNode fParent;
+
+
+ /**
+ * Creates a RubyNode under the given parent.
+ * @param type the Ruby elements type. Legal values are from the range CU to METHOD of this class.
+ * @param name the name of the Ruby element
+ * @param start the starting position of the java element in the underlying document
+ * @param length the number of characters of the java element in the underlying document
+ */
+ public RubyNode(RubyNode parent, int type, String name, int start, int length) {
+ super(type, RubyCompareUtilities.buildID(type, name), parent.getDocument(), start, length);
+ fParent= parent;
+ if (parent != null) {
+ parent.addChild(this);
+ fIsEditable= parent.isEditable();
+ }
+ }
+
+ /**
+ * Creates a RubyNode for a CU. It represents the root of a
+ * RubyNode tree, so its parent is null.
+ * @param document the document which contains the Ruby element
+ * @param editable whether the document can be modified
+ */
+ public RubyNode(IDocument document, boolean editable) {
+ super(SCRIPT, RubyCompareUtilities.buildID(SCRIPT, "root"), document, 0, document.getLength()); //$NON-NLS-1$
+ fIsEditable= editable;
+ }
+
+ public String getInitializerCount() {
+ return Integer.toString(fInitializerCount++);
+ }
+
+ /**
+ * Extracts the method name from the signature.
+ * Used for smart matching.
+ */
+ public String extractMethodName() {
+ String id= getId();
+ int pos= id.indexOf('(');
+ if (pos > 0)
+ return id.substring(1, pos);
+ return id.substring(1);
+ }
+
+ /**
+ * Extracts the method's arguments name the signature.
+ * Used for smart matching.
+ */
+ public String extractArgumentList() {
+ String id= getId();
+ int pos= id.indexOf('(');
+ if (pos >= 0)
+ return id.substring(pos+1);
+ return id.substring(1);
+ }
+
+ /**
+ * Returns a name which is presented in the UI.
+ * @see ITypedElement#getName()
+ */
+ public String getName() {
+
+ switch (getTypeCode()) {
+ case IMPORT_CONTAINER:
+ return CompareMessages.RubyNode_importDeclarations;
+ case SCRIPT:
+ return CompareMessages.RubyNode_script;
+ }
+ return getId().substring(1); // we strip away the type character
+ }
+
+ /*
+ * @see ITypedElement#getType()
+ */
+ public String getType() {
+ return "java2"; //$NON-NLS-1$
+ }
+
+ /* (non Rubydoc)
+ * see IEditableContent.isEditable
+ */
+ public boolean isEditable() {
+ return fIsEditable;
+ }
+
+ /**
+ * Returns a shared image for this Ruby element.
+ *
+ * see ITypedInput.getImage
+ */
+ public Image getImage() {
+
+ ImageDescriptor id= null;
+
+ switch (getTypeCode()) {
+ case SCRIPT:
+ id= RubyCompareUtilities.getImageDescriptor(IRubyElement.SCRIPT);
+ break;
+ case IMPORT:
+ id= RubyCompareUtilities.getImageDescriptor(IRubyElement.IMPORT_DECLARATION);
+ break;
+ case IMPORT_CONTAINER:
+ id= RubyCompareUtilities.getImageDescriptor(IRubyElement.IMPORT_CONTAINER);
+ break;
+ case CLASS:
+ id= RubyCompareUtilities.getTypeImageDescriptor(true);
+ break;
+ case MODULE:
+ id= RubyCompareUtilities.getTypeImageDescriptor(false);
+ break;
+ case CONSTRUCTOR:
+ case METHOD:
+ id= RubyCompareUtilities.getImageDescriptor(IRubyElement.METHOD);
+ break;
+ case FIELD:
+ id= RubyCompareUtilities.getImageDescriptor(IRubyElement.FIELD);
+ break;
+ }
+ return RubyPlugin.getImageDescriptorRegistry().get(id);
+ }
+
+ public void setContent(byte[] content) {
+ super.setContent(content);
+ nodeChanged(this);
+ }
+
+ public ITypedElement replace(ITypedElement child, ITypedElement other) {
+ nodeChanged(this);
+ return child;
+ }
+
+ void nodeChanged(RubyNode node) {
+ if (fParent != null)
+ fParent.nodeChanged(node);
+ }
+}
+
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewer.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewer.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.compare;
+
+import org.eclipse.compare.IStreamContentAccessor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
+import org.rubypeople.rdt.ui.text.RubySourceViewerConfiguration;
+import org.rubypeople.rdt.ui.text.RubyTextTools;
+
+
+public class RubyTextViewer extends Viewer {
+
+ private SourceViewer fSourceViewer;
+ private Object fInput;
+
+
+ RubyTextViewer(Composite parent) {
+ fSourceViewer= new SourceViewer(parent, null, SWT.LEFT_TO_RIGHT | SWT.H_SCROLL | SWT.V_SCROLL);
+ RubyTextTools tools= RubyCompareUtilities.getRubyTextTools();
+ if (tools != null) {
+ IPreferenceStore store= RubyPlugin.getDefault().getCombinedPreferenceStore();
+ fSourceViewer.configure(new RubySourceViewerConfiguration(tools.getColorManager(), store, null, IRubyPartitions.RUBY_PARTITIONING));
+ }
+
+ fSourceViewer.setEditable(false);
+
+ String symbolicFontName= RubyMergeViewer.class.getName();
+ Font font= JFaceResources.getFont(symbolicFontName);
+ if (font != null)
+ fSourceViewer.getTextWidget().setFont(font);
+
+ }
+
+ public Control getControl() {
+ return fSourceViewer.getControl();
+ }
+
+ public void setInput(Object input) {
+ if (input instanceof IStreamContentAccessor) {
+ Document document= new Document(getString(input));
+ RubyCompareUtilities.setupDocument(document);
+ fSourceViewer.setDocument(document);
+ }
+ fInput= input;
+ }
+
+ public Object getInput() {
+ return fInput;
+ }
+
+ public ISelection getSelection() {
+ return null;
+ }
+
+ public void setSelection(ISelection s, boolean reveal) {
+ }
+
+ public void refresh() {
+ }
+
+ /**
+ * A helper method to retrieve the contents of the given object
+ * if it implements the IStreamContentAccessor interface.
+ */
+ private static String getString(Object input) {
+
+ if (input instanceof IStreamContentAccessor) {
+ IStreamContentAccessor sca= (IStreamContentAccessor) input;
+ try {
+ return RubyCompareUtilities.readString(sca);
+ } catch (CoreException ex) {
+ RubyPlugin.log(ex);
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+}
+
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewerCreator.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewerCreator.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/compare/RubyTextViewerCreator.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.compare;
+
+import org.eclipse.swt.widgets.Composite;
+
+import org.eclipse.jface.viewers.Viewer;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.IViewerCreator;
+
+
+/**
+ * A factory object for the <code>RubyTextViewer</code>.
+ * This indirection is necessary because only objects with a default
+ * constructor can be created via an extension point
+ * (this precludes Viewers).
+ */
+public class RubyTextViewerCreator implements IViewerCreator {
+
+ public Viewer createViewer(Composite parent, CompareConfiguration mp) {
+ return new RubyTextViewer(parent);
+ }
+}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-12-06 15:01:06 UTC (rev 1678)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-12-06 15:31:27 UTC (rev 1679)
@@ -30,6 +30,7 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
@@ -138,9 +139,22 @@
}
@Override
- public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
- ITextEditor editor = getEditor();
- return new IHyperlinkDetector[]{new RubyHyperLinkDetector(editor.getEditorInput())};
+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+ if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
+ return null;
+
+ IHyperlinkDetector[] inheritedDetectors= super.getHyperlinkDetectors(sourceViewer);
+
+ if (fTextEditor == null)
+ return inheritedDetectors;
+
+ int inheritedDetectorsLength= inheritedDetectors != null ? inheritedDetectors.length : 0;
+ IHyperlinkDetector[] detectors= new IHyperlinkDetector[inheritedDetectorsLength + 1];
+ detectors[0]= new RubyHyperLinkDetector(fTextEditor.getEditorInput());
+ for (int i= 0; i < inheritedDetectorsLength; i++)
+ detectors[i+1]= inheritedDetectors[i];
+
+ return detectors;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|