2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
18 import org
.apache
.commons
.logging
.Log
;
19 import org
.apache
.commons
.logging
.LogFactory
;
20 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
21 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
22 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
23 import org
.argeo
.slc
.repo
.JavaRepoManager
;
24 import org
.eclipse
.core
.commands
.AbstractHandler
;
25 import org
.eclipse
.core
.commands
.ExecutionEvent
;
26 import org
.eclipse
.core
.commands
.ExecutionException
;
27 import org
.eclipse
.jface
.dialogs
.Dialog
;
28 import org
.eclipse
.jface
.dialogs
.InputDialog
;
29 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
30 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
32 /** Create a new empty workspace in the default local java repository */
33 public class CreateLocalJavaWorkspace
extends AbstractHandler
{
34 private static final Log log
= LogFactory
35 .getLog(CreateLocalJavaWorkspace
.class);
37 // Exposes commands meta-info
38 public final static String ID
= DistPlugin
.PLUGIN_ID
39 + ".createLocalJavaWorkspace";
40 public final static String DEFAULT_LABEL
= "Create local Java workspace...";
41 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
42 .getImageDescriptor("icons/addItem.gif");
45 public final static String PARAM_WORKSPACE_PREFIX
= "workspacePrefix";
47 /* DEPENDENCY INJECTION */
48 private JavaRepoManager javaRepoManager
;
50 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
52 String prefix
= event
.getParameter(PARAM_WORKSPACE_PREFIX
);
53 // TODO : add an input validator
54 InputDialog inputDialog
= new InputDialog(HandlerUtil
55 .getActiveWorkbenchWindow(event
).getShell(), "Workspace name?",
56 "Choose a name for the workspace to create",
57 prefix
== null ?
"" : prefix
+ "-", null);
58 int result
= inputDialog
.open();
60 String enteredName
= inputDialog
.getValue();
61 final String legalChars
= "ABCDEFGHIJKLMNOPQRSTUVWXZY0123456789_";
62 char[] arr
= enteredName
.toUpperCase().toCharArray();
64 for (int i
= 0; i
< arr
.length
; i
++) {
65 if (legalChars
.indexOf(arr
[i
]) == -1)
72 ErrorFeedback
.show("Workspace name '" + enteredName
73 + "' is too long or contains"
74 + " too many special characters such as '.' or '-'.");
78 String workspaceName
= enteredName
;
80 if (result
== Dialog
.CANCEL
|| workspaceName
== null
81 || "".equals(workspaceName
.trim()))
84 // FIXME will throw an exception if this workspace name is already used.
85 javaRepoManager
.createWorkspace(workspaceName
);
87 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
88 if (log
.isTraceEnabled())
89 log
.trace("WORKSPACE " + workspaceName
+ " CREATED");
94 /* DEPENDENCY INJECTION */
95 public void setJavaRepoManager(JavaRepoManager javaRepoManager
) {
96 this.javaRepoManager
= javaRepoManager
;