1 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
6 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
7 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
8 import org
.argeo
.slc
.repo
.JavaRepoManager
;
9 import org
.eclipse
.core
.commands
.AbstractHandler
;
10 import org
.eclipse
.core
.commands
.ExecutionEvent
;
11 import org
.eclipse
.core
.commands
.ExecutionException
;
12 import org
.eclipse
.jface
.dialogs
.Dialog
;
13 import org
.eclipse
.jface
.dialogs
.InputDialog
;
14 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
15 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
17 /** Create a new empty workspace in the default local java repository */
18 public class CreateLocalJavaWorkspace
extends AbstractHandler
{
19 private static final Log log
= LogFactory
20 .getLog(CreateLocalJavaWorkspace
.class);
22 // Exposes commands meta-info
23 public final static String ID
= DistPlugin
.PLUGIN_ID
24 + ".createLocalJavaWorkspace";
25 public final static String DEFAULT_LABEL
= "Create local Java workspace...";
26 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
27 .getImageDescriptor("icons/addItem.gif");
30 public final static String PARAM_WORKSPACE_PREFIX
= "workspacePrefix";
32 /* DEPENDENCY INJECTION */
33 private JavaRepoManager javaRepoManager
;
35 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
37 String prefix
= event
.getParameter(PARAM_WORKSPACE_PREFIX
);
38 // TODO : add an input validator
39 InputDialog inputDialog
= new InputDialog(HandlerUtil
40 .getActiveWorkbenchWindow(event
).getShell(), "Workspace name?",
41 "Choose a name for the workspace to create",
42 prefix
== null ?
"" : prefix
+ "-", null);
43 int result
= inputDialog
.open();
45 String enteredName
= inputDialog
.getValue();
46 final String legalChars
= "ABCDEFGHIJKLMNOPQRSTUVWXZY0123456789_";
47 char[] arr
= enteredName
.toUpperCase().toCharArray();
49 for (int i
= 0; i
< arr
.length
; i
++) {
50 if (legalChars
.indexOf(arr
[i
]) == -1)
57 ErrorFeedback
.show("Workspace name '" + enteredName
58 + "' is too long or contains"
59 + " too many special characters such as '.' or '-'.");
63 String workspaceName
= enteredName
;
65 if (result
== Dialog
.CANCEL
|| workspaceName
== null
66 || "".equals(workspaceName
.trim()))
69 // FIXME will throw an exception if this workspace name is already used.
70 javaRepoManager
.createWorkspace(workspaceName
);
72 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
73 if (log
.isTraceEnabled())
74 log
.trace("WORKSPACE " + workspaceName
+ " CREATED");
79 /* DEPENDENCY INJECTION */
80 public void setJavaRepoManager(JavaRepoManager javaRepoManager
) {
81 this.javaRepoManager
= javaRepoManager
;