Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-07-19 08:22:04 +0000
committerEike Stepper2012-07-19 08:22:04 +0000
commit1460904fd3c193ffaf809913b2983a400fce9d94 (patch)
tree72f3a17b75fedba3ae1060df1d32c9c7889be954 /plugins/org.eclipse.emf.cdo.releng.relativepaths
parent5f360965ae87478e0681899bf310a210cafc2c44 (diff)
downloadcdo-1460904fd3c193ffaf809913b2983a400fce9d94.tar.gz
cdo-1460904fd3c193ffaf809913b2983a400fce9d94.tar.xz
cdo-1460904fd3c193ffaf809913b2983a400fce9d94.zip
Fix line endings in master (dos2unix)
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.releng.relativepaths')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/.classpath14
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/.project56
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/.settings/org.eclipse.core.resources.prefs6
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/about.properties62
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/copyright.txt14
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.properties22
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.xml82
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/Activator.java96
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/CreateRelativePathAction.java324
9 files changed, 338 insertions, 338 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/.classpath b/plugins/org.eclipse.emf.cdo.releng.relativepaths/.classpath
index 2d1a4302f0..64c5e31b7a 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/.classpath
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/.classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/.project b/plugins/org.eclipse.emf.cdo.releng.relativepaths/.project
index c8f4162e5b..302586ee92 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/.project
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/.project
@@ -1,28 +1,28 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.emf.cdo.releng.relativepaths</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.cdo.releng.relativepaths</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/.settings/org.eclipse.core.resources.prefs b/plugins/org.eclipse.emf.cdo.releng.relativepaths/.settings/org.eclipse.core.resources.prefs
index 93c8fd514e..b02ec790ac 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/.settings/org.eclipse.core.resources.prefs
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/.settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,3 @@
-#Mon Jul 11 16:02:45 CEST 2011
-eclipse.preferences.version=1
-encoding//model/org.eclipse.emf.cdo.defs.ecorediag=UTF-8
+#Mon Jul 11 16:02:45 CEST 2011
+eclipse.preferences.version=1
+encoding//model/org.eclipse.emf.cdo.defs.ecorediag=UTF-8
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/about.properties b/plugins/org.eclipse.emf.cdo.releng.relativepaths/about.properties
index 4d661bce76..1244363085 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/about.properties
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/about.properties
@@ -1,31 +1,31 @@
-# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
-# Eike Stepper - initial API and implementation
-
-# NLS_MESSAGEFORMAT_VAR
-
-# ==============================================================================
-# Do not change the properties between this line and the last line containing:
-# %%% END OF TRANSLATED PROPERTIES %%%
-# Instead, either redefine an existing property, or create a new property,
-# append it to the end of the file, and change the code to use the new name.
-# ==============================================================================
-
-featureName = CDO Release Engineering Relative Paths
-featureText = CDO Release Engineering Relative Paths\n\
-Version: {featureVersion}\n\
-Build id: {0}\n\
-\n\
-Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. All rights reserved.\n\
-\n\
-Visit http://www.eclipse.org/cdo
-
-# ==============================================================================
-# %%% END OF TRANSLATED PROPERTIES %%%
-# The above properties have been shipped for translation.
-# ==============================================================================
+# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+# Eike Stepper - initial API and implementation
+
+# NLS_MESSAGEFORMAT_VAR
+
+# ==============================================================================
+# Do not change the properties between this line and the last line containing:
+# %%% END OF TRANSLATED PROPERTIES %%%
+# Instead, either redefine an existing property, or create a new property,
+# append it to the end of the file, and change the code to use the new name.
+# ==============================================================================
+
+featureName = CDO Release Engineering Relative Paths
+featureText = CDO Release Engineering Relative Paths\n\
+Version: {featureVersion}\n\
+Build id: {0}\n\
+\n\
+Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. All rights reserved.\n\
+\n\
+Visit http://www.eclipse.org/cdo
+
+# ==============================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# The above properties have been shipped for translation.
+# ==============================================================================
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/copyright.txt b/plugins/org.eclipse.emf.cdo.releng.relativepaths/copyright.txt
index 8f6328980e..0a0f67e6d7 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/copyright.txt
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/copyright.txt
@@ -1,8 +1,8 @@
-Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
Eike Stepper - initial API and implementation \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.properties b/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.properties
index 921b1864f3..8ca078ce04 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.properties
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.properties
@@ -1,11 +1,11 @@
-# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
-# Eike Stepper - initial API and implementation
-
-pluginName = CDO Release Engineering Relative Paths
-providerName = Eclipse Modeling Project
+# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+# Eike Stepper - initial API and implementation
+
+pluginName = CDO Release Engineering Relative Paths
+providerName = Eclipse Modeling Project
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.xml b/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.xml
index b5f60a82c8..85e1aed162 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/plugin.xml
@@ -1,41 +1,41 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<!--
- Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- Eike Stepper - initial API and implementation
--->
-
-<plugin>
-
- <extension
- point="org.eclipse.ui.popupMenus">
- <objectContribution
- adaptable="true"
- id="org.eclipse.emf.cdo.releng.relativepaths.contribution1"
- objectClass="org.eclipse.core.resources.IResource">
- <menu
- id="org.eclipse.emf.cdo.releng"
- label="CDO Release Engineering"
- path="additions">
- <separator
- name="group1">
- </separator>
- </menu>
- <action
- class="org.eclipse.emf.cdo.releng.relativepaths.CreateRelativePathAction"
- enablesFor="1"
- id="org.eclipse.emf.cdo.releng.CreateRelativePathAction"
- label="Create Relative Path..."
- menubarPath="org.eclipse.emf.cdo.releng/group1"
- style="push">
- </action>
- </objectContribution>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<!--
+ Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ Eike Stepper - initial API and implementation
+-->
+
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ adaptable="true"
+ id="org.eclipse.emf.cdo.releng.relativepaths.contribution1"
+ objectClass="org.eclipse.core.resources.IResource">
+ <menu
+ id="org.eclipse.emf.cdo.releng"
+ label="CDO Release Engineering"
+ path="additions">
+ <separator
+ name="group1">
+ </separator>
+ </menu>
+ <action
+ class="org.eclipse.emf.cdo.releng.relativepaths.CreateRelativePathAction"
+ enablesFor="1"
+ id="org.eclipse.emf.cdo.releng.CreateRelativePathAction"
+ label="Create Relative Path..."
+ menubarPath="org.eclipse.emf.cdo.releng/group1"
+ style="push">
+ </action>
+ </objectContribution>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/Activator.java b/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/Activator.java
index 7959fcfede..a512931aed 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/Activator.java
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/Activator.java
@@ -1,48 +1,48 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.releng.relativepaths;
-
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-import org.osgi.framework.BundleContext;
-
-/**
- * @author Eike Stepper
- */
-public class Activator extends AbstractUIPlugin
-{
- public static final String PLUGIN_ID = "org.eclipse.emf.cdo.releng.relativepaths"; //$NON-NLS-1$
-
- private static Activator plugin;
-
- public Activator()
- {
- }
-
- @Override
- public void start(BundleContext context) throws Exception
- {
- super.start(context);
- plugin = this;
- }
-
- @Override
- public void stop(BundleContext context) throws Exception
- {
- plugin = null;
- super.stop(context);
- }
-
- public static Activator getDefault()
- {
- return plugin;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.releng.relativepaths;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Eike Stepper
+ */
+public class Activator extends AbstractUIPlugin
+{
+ public static final String PLUGIN_ID = "org.eclipse.emf.cdo.releng.relativepaths"; //$NON-NLS-1$
+
+ private static Activator plugin;
+
+ public Activator()
+ {
+ }
+
+ @Override
+ public void start(BundleContext context) throws Exception
+ {
+ super.start(context);
+ plugin = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception
+ {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static Activator getDefault()
+ {
+ return plugin;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/CreateRelativePathAction.java b/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/CreateRelativePathAction.java
index 912e910fb3..b145b0b6c4 100644
--- a/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/CreateRelativePathAction.java
+++ b/plugins/org.eclipse.emf.cdo.releng.relativepaths/src/org/eclipse/emf/cdo/releng/relativepaths/CreateRelativePathAction.java
@@ -1,162 +1,162 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.releng.relativepaths;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public class CreateRelativePathAction implements IObjectActionDelegate
-{
- private static final String TITLE = "Create Relative Path";
-
- private Shell shell;
-
- private ISelection selection;
-
- public CreateRelativePathAction()
- {
- }
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart)
- {
- shell = targetPart.getSite().getShell();
- }
-
- public void selectionChanged(IAction action, ISelection selection)
- {
- this.selection = selection;
- }
-
- @SuppressWarnings("restriction")
- public void run(IAction action)
- {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IResource source = (IResource)((IStructuredSelection)selection).getFirstElement();
-
- org.eclipse.ui.internal.ide.dialogs.OpenResourceDialog dialog = new org.eclipse.ui.internal.ide.dialogs.OpenResourceDialog(
- shell, root, IResource.FILE);
- dialog.setTitle(TITLE);
-
- if (dialog.open() == Dialog.OK)
- {
- IResource target = (IResource)dialog.getResult()[0];
- String link = createLink(source, target);
-
- copyToClipboard(shell.getDisplay(), link);
- MessageDialog.openInformation(shell, TITLE, "The following relative path has been copied to the clipboard:\n"
- + link);
- }
- }
-
- public static String createLink(IResource source, IResource target)
- {
- return createLink(new File(source.getLocation().toString()), new File(target.getLocation().toString()));
- }
-
- public static String createLink(File source, File target)
- {
- List<String> sourceSegments = getSegments(source);
- List<String> targetSegments = getSegments(target);
-
- int minSize = Math.min(sourceSegments.size(), targetSegments.size());
- for (int i = 0; i < minSize; i++)
- {
- if (sourceSegments.get(0).equals(targetSegments.get(0)))
- {
- sourceSegments.remove(0);
- targetSegments.remove(0);
- }
- else
- {
- break;
- }
- }
-
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < sourceSegments.size() - 1; i++)
- {
- builder.append("../");
- }
-
- boolean first = true;
- for (String segment : targetSegments)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- builder.append("/");
- }
-
- builder.append(segment);
- }
-
- return builder.toString();
- }
-
- private static List<String> getSegments(File file)
- {
- List<String> result = new ArrayList<String>();
- getSegments(file, result);
- return result;
- }
-
- private static void getSegments(File file, List<String> result)
- {
- File parent = file.getParentFile();
- if (parent != null)
- {
- getSegments(parent, result);
- }
-
- result.add(file.getName());
- }
-
- public static void copyToClipboard(Display display, String text)
- {
- Clipboard clipboard = null;
-
- try
- {
- clipboard = new Clipboard(display);
- clipboard.setContents(new Object[] { text }, new Transfer[] { TextTransfer.getInstance() });
- }
- finally
- {
- if (clipboard != null)
- {
- clipboard.dispose();
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.releng.relativepaths;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class CreateRelativePathAction implements IObjectActionDelegate
+{
+ private static final String TITLE = "Create Relative Path";
+
+ private Shell shell;
+
+ private ISelection selection;
+
+ public CreateRelativePathAction()
+ {
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart)
+ {
+ shell = targetPart.getSite().getShell();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ this.selection = selection;
+ }
+
+ @SuppressWarnings("restriction")
+ public void run(IAction action)
+ {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource source = (IResource)((IStructuredSelection)selection).getFirstElement();
+
+ org.eclipse.ui.internal.ide.dialogs.OpenResourceDialog dialog = new org.eclipse.ui.internal.ide.dialogs.OpenResourceDialog(
+ shell, root, IResource.FILE);
+ dialog.setTitle(TITLE);
+
+ if (dialog.open() == Dialog.OK)
+ {
+ IResource target = (IResource)dialog.getResult()[0];
+ String link = createLink(source, target);
+
+ copyToClipboard(shell.getDisplay(), link);
+ MessageDialog.openInformation(shell, TITLE, "The following relative path has been copied to the clipboard:\n"
+ + link);
+ }
+ }
+
+ public static String createLink(IResource source, IResource target)
+ {
+ return createLink(new File(source.getLocation().toString()), new File(target.getLocation().toString()));
+ }
+
+ public static String createLink(File source, File target)
+ {
+ List<String> sourceSegments = getSegments(source);
+ List<String> targetSegments = getSegments(target);
+
+ int minSize = Math.min(sourceSegments.size(), targetSegments.size());
+ for (int i = 0; i < minSize; i++)
+ {
+ if (sourceSegments.get(0).equals(targetSegments.get(0)))
+ {
+ sourceSegments.remove(0);
+ targetSegments.remove(0);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < sourceSegments.size() - 1; i++)
+ {
+ builder.append("../");
+ }
+
+ boolean first = true;
+ for (String segment : targetSegments)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ builder.append("/");
+ }
+
+ builder.append(segment);
+ }
+
+ return builder.toString();
+ }
+
+ private static List<String> getSegments(File file)
+ {
+ List<String> result = new ArrayList<String>();
+ getSegments(file, result);
+ return result;
+ }
+
+ private static void getSegments(File file, List<String> result)
+ {
+ File parent = file.getParentFile();
+ if (parent != null)
+ {
+ getSegments(parent, result);
+ }
+
+ result.add(file.getName());
+ }
+
+ public static void copyToClipboard(Display display, String text)
+ {
+ Clipboard clipboard = null;
+
+ try
+ {
+ clipboard = new Clipboard(display);
+ clipboard.setContents(new Object[] { text }, new Transfer[] { TextTransfer.getInstance() });
+ }
+ finally
+ {
+ if (clipboard != null)
+ {
+ clipboard.dispose();
+ }
+ }
+ }
+}

Back to the top