Permalink
Browse files

Fixes #1998.

Signed-off-by: AlexisDrogoul <alexis.drogoul@gmail.com>
  • Loading branch information...
1 parent 20f64ca commit c48bc53ca7ef7081cf7ab6bbca6abe591ec37969 @AlexisDrogoul AlexisDrogoul committed Sep 22, 2016
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?pde version="3.8"?><target name="GAMA target platform" sequenceNumber="24">
+<?pde version="3.8"?><target name="GAMA target platform" sequenceNumber="25">
<locations>
<location path="${eclipse_home}" type="Profile"/>
-<location includeAllPlatforms="true" includeConfigurePhase="true" includeMode="slicer" includeSource="true" type="InstallableUnit">
+<location includeAllPlatforms="true" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.rcp.feature.group" version="4.5.2.v20160212-1500"/>
<unit id="org.eclipse.rcp.source.feature.group" version="4.5.2.v20160212-1500"/>
<repository location="http://download.eclipse.org/eclipse/updates/4.5"/>
</location>
+<location includeAllPlatforms="true" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
+<unit id="org.eclipse.core.expressions" version="3.5.0.v20150421-2214"/>
+</location>
</locations>
</target>
-
@@ -317,39 +317,45 @@ protected void execute(final IProgressMonitor monitor)
public static String UNCLASSIFIED_MODELS = "Unclassified Models";
- private IFile createUnclassifiedModelsProjectAndAdd(final IPath location) {
+ public IFolder createUnclassifiedModelsProject(final IPath location) throws CoreException {
// First allow to select a parent folder
final ContainerSelectionDialog dialog = new ContainerSelectionDialog(Display.getDefault().getActiveShell(),
- null, false, "Select a parent project:");
+ null, false, "Select a parent project or cancel to create a new project:");
dialog.setTitle("Project selection");
dialog.showClosedProjects(false);
final int result = dialog.open();
IProject project;
IFolder modelFolder;
- IFile iFile = null;
- try {
- if ( result == MessageDialog.CANCEL ) {
- project = createOrUpdateProject(UNCLASSIFIED_MODELS);
+
+ if ( result == MessageDialog.CANCEL ) {
+ project = createOrUpdateProject(UNCLASSIFIED_MODELS);
+ modelFolder = project.getFolder(new Path("models"));
+ if ( !modelFolder.exists() ) {
+ modelFolder.create(true, true, null);
+ }
+ } else {
+ final IContainer container = (IContainer) dialog.getResult()[0];
+ if ( container instanceof IProject ) {
+ project = (IProject) container;
modelFolder = project.getFolder(new Path("models"));
if ( !modelFolder.exists() ) {
modelFolder.create(true, true, null);
}
} else {
- final IContainer container = (IContainer) dialog.getResult()[0];
- if ( container instanceof IProject ) {
- project = (IProject) container;
- modelFolder = project.getFolder(new Path("models"));
- if ( !modelFolder.exists() ) {
- modelFolder.create(true, true, null);
- }
- } else {
- project = container.getProject();
- modelFolder = (IFolder) container;
- }
-
+ project = container.getProject();
+ modelFolder = (IFolder) container;
}
+ }
+
+ return modelFolder;
+ }
+
+ private IFile createUnclassifiedModelsProjectAndAdd(final IPath location) {
+ IFile iFile = null;
+ try {
+ final IFolder modelFolder = createUnclassifiedModelsProject(location);
iFile = modelFolder.getFile(location.lastSegment());
if ( iFile.exists() ) {
if ( iFile.isLinked() ) {
@@ -520,7 +526,7 @@ protected void execute(final IProgressMonitor monitor)
}
- static private IProject createOrUpdateProject(final String name) {
+ static public IProject createOrUpdateProject(final String name) {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final IProject[] projectHandle = new IProject[] { null };
final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@@ -639,4 +645,16 @@ public static String getCurrentGamaStampString() {
return gamaStamp;
}
+ public boolean isGamaProject(final File f) throws CoreException {
+ for ( final String s : f.list() ) {
+ if ( s.equals(".project") ) {
+ IPath p = new Path(f.getAbsolutePath());
+ p = p.append(".project");
+ final IProjectDescription pd = ResourcesPlugin.getWorkspace().loadProjectDescription(p);
+ if ( pd.hasNature(this.GAMA_NATURE) ) { return true; }
+ }
+ }
+ return false;
+ }
+
}
@@ -16,7 +16,8 @@ Require-Bundle: ummisco.gama.ui.shared,
org.eclipse.ui.navigator.resources;bundle-version="3.5.1",
msi.gama.core,
msi.gama.application,
- msi.gama.ext;bundle-version="1.7.0"
+ msi.gama.ext;bundle-version="1.7.0",
+ org.eclipse.core.expressions;bundle-version="3.5.0"
Bundle-ActivationPolicy: lazy
Export-Package: ummisco.gama.ui.commands,
ummisco.gama.ui.metadata,
@@ -163,16 +163,16 @@
style="push">
<visibleWhen
checkEnabled="true">
- <and>
- <iterate>
- <adapt
- type="org.eclipse.core.resources.IProject">
- </adapt>
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <instanceof
+ value="org.eclipse.core.resources.IProject">
+ </instanceof>
</iterate>
- <count
- value="+">
- </count>
- </and>
+ </with>
</visibleWhen>
</command>
<separator
@@ -315,9 +315,6 @@
pattern="org.eclipse.ui.navigator.resources.UndoRedoActionProvider">
</actionExtension>
<actionExtension
- pattern="org.eclipse.ui.navigator.resources.PropertiesActionProvider">
- </actionExtension>
- <actionExtension
pattern="org.eclipse.ui.navigator.resources.RefactorActions">
</actionExtension>
<actionExtension
@@ -334,6 +331,9 @@
<actionExtension
pattern="org.eclipse.ui.navigator.resources.WorkingSetActionProvider">
</actionExtension>
+ <actionExtension
+ pattern="org.eclipse.ui.navigator.resources.PropertiesActionProvider">
+ </actionExtension>
</excludes>
</viewerActionBinding>
<viewerContentBinding
@@ -361,6 +361,9 @@
class="org.eclipse.ui.navigator.resources.ResourceDragAdapterAssistant"
viewerId="msi.gama.gui.view.GamaNavigator">
</dragAssistant>
+ <viewer
+ viewerId="msi.gama.gui.view.GamaNavigator">
+ </viewer>
</extension>
<extension
point="org.eclipse.ui.navigator.navigatorContent">
@@ -431,13 +434,29 @@
class="ummisco.gama.ui.navigator.NavigatorDropAssistant"
id="msi.gama.application.dropAssistant1">
<possibleDropTargets>
- <or>
- <instanceof
- value="ummisco.gama.ui.navigator.VirtualContent">
- </instanceof>
- </or>
+ <instanceof
+ value="java.lang.Object">
+ </instanceof>
</possibleDropTargets>
</dropAssistant>
+ <actionProvider
+ class="ummisco.gama.ui.navigator.NavigatorActionprovider">
+ <enablement>
+ <and>
+ <or>
+ <instanceof
+ value="ummisco.gama.ui.navigator.NavigatorRoot">
+ </instanceof>
+ <instanceof
+ value="ummisco.gama.ui.navigator.UserProjectsFolder">
+ </instanceof>
+ </or>
+ <test
+ property="ummisco.gama.cbready">
+ </test>
+ </and>
+ </enablement>
+ </actionProvider>
</navigatorContent>
<commonFilter
activeByDefault="true"
@@ -544,5 +563,15 @@
serviceClass="msi.gama.util.file.IFileMetaDataProvider"></service>
</serviceFactory>
</extension>
+ <extension
+point="org.eclipse.core.expressions.propertyTesters">
+<propertyTester
+class="ummisco.gama.ui.navigator.ClipboardTester"
+id="ummisco.gama.clipboard.tester"
+namespace="ummisco.gama"
+properties="cbready"
+type="java.lang.Object">
+</propertyTester>
+</extension>
</plugin>
@@ -11,7 +11,11 @@
**********************************************************************************************/
package ummisco.gama.ui.commands;
-import org.eclipse.core.commands.*;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.NotEnabledException;
+import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.IHandlerService;
@@ -20,35 +24,21 @@
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
- IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
+ final IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
try {
handlerService.executeCommand("org.eclipse.ui.edit.copy", null);
handlerService.executeCommand("org.eclipse.ui.edit.paste", null);
- // handlerService.executeCommand("org.eclipse.team.svn.ui.command.DisconnectCommand", null);
+ // handlerService.executeCommand("org.eclipse.team.svn.ui.command.DisconnectCommand",
+ // null);
// deleteMetaSvn(path);
- } catch (NotDefinedException e) {
+ } catch (final NotDefinedException e) {
e.printStackTrace();
- } catch (NotEnabledException e) {
+ } catch (final NotEnabledException e) {
e.printStackTrace();
- } catch (NotHandledException e) {
+ } catch (final NotHandledException e) {
e.printStackTrace();
}
- // RefreshHandler.run();
return null;
}
- //
- // private void deleteMetaSvn(File path) {
- // File[] files = path.listFiles();
- // for(int i=0; i<files.length; i++) {
- // String name = files[i].getName();
- // if(files[i].isDirectory() && !name.equals(".svn")) {
- // deleteMetaSvn(files[i]);
- // }
- // else {
- // if(name.equals(".svn"))
- // files[i].delete();
- // }
- // }
- // }
}
@@ -0,0 +1,87 @@
+package ummisco.gama.ui.commands;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
+
+import msi.gama.application.workspace.WorkspaceModelsManager;
+import ummisco.gama.ui.utils.WorkbenchHelper;
+
+public class PasteIntoModelsHandler extends AbstractHandler {
+
+ public static void handlePaste(final String[] selection) {
+ for (final String name : selection) {
+ final File f = new File(name);
+ IContainer container;
+ if (f.isDirectory()) {
+ try {
+ if (WorkspaceModelsManager.instance.isGamaProject(f)) {
+ container = WorkspaceModelsManager.createOrUpdateProject(f.getName());
+ final CopyFilesAndFoldersOperation op = new CopyFilesAndFoldersOperation(
+ WorkbenchHelper.getShell());
+ op.setVirtualFolders(false);
+ final List<File> files = Arrays.asList(f.listFiles());
+ final List<String> names = new ArrayList();
+ for (final File toCopy : files) {
+ if (toCopy.getName().equals(".project"))
+ continue;
+ names.add(toCopy.getAbsolutePath());
+ }
+ op.copyFiles(names.toArray(new String[0]), container);
+ } else {
+ container = WorkspaceModelsManager.instance.createUnclassifiedModelsProject(new Path(name));
+ final CopyFilesAndFoldersOperation op = new CopyFilesAndFoldersOperation(
+ WorkbenchHelper.getShell());
+ op.setVirtualFolders(false);
+ op.copyFiles(new String[] { name }, container);
+ }
+ } catch (final CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ container = WorkspaceModelsManager.instance.createUnclassifiedModelsProject(new Path(name));
+ final CopyFilesAndFoldersOperation op = new CopyFilesAndFoldersOperation(
+ WorkbenchHelper.getShell());
+ op.setVirtualFolders(false);
+ op.copyFiles(new String[] { name }, container);
+ } catch (final CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public static void handlePaste() {
+ final Clipboard clipBoard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
+ final FileTransfer transfer = FileTransfer.getInstance();
+ final String[] selection = (String[]) clipBoard.getContents(transfer);
+ if (selection != null && selection.length != 0)
+ handlePaste(selection);
+ clipBoard.dispose();
+ }
+
+ @Override
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ final Clipboard clipBoard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
+ final FileTransfer transfer = FileTransfer.getInstance();
+ final String[] selection = (String[]) clipBoard.getContents(transfer);
+ handlePaste(selection);
+ return this;
+ }
+
+}
@@ -0,0 +1,18 @@
+package ummisco.gama.ui.navigator;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.ui.PlatformUI;
+
+public class ClipboardTester extends PropertyTester {
+
+ @Override
+ public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
+ final Clipboard clipBoard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
+ final FileTransfer transfer = FileTransfer.getInstance();
+ final String[] selection = (String[]) clipBoard.getContents(transfer);
+ return selection != null;
+ }
+
+}
@@ -127,6 +127,8 @@ public void createPartControl(final Composite compo) {
} catch (final CoreException e) {
e.printStackTrace();
}
+ getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.PASTE.getId(), PasteAction.INSTANCE);
+ getViewSite().getActionBars().updateActionBars();
}
@Override
Oops, something went wrong.

0 comments on commit c48bc53

Please sign in to comment.