]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateLocalJavaWorkspace.java
Fix file download for rap. Add various links in the bundle detail editor.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / CreateLocalJavaWorkspace.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.client.ui.dist.commands;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.argeo.eclipse.ui.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;
31
32 /**
33 * Create a new empty workspace in the default local java repository.
34 */
35 public class CreateLocalJavaWorkspace extends AbstractHandler {
36 private static final Log log = LogFactory
37 .getLog(CreateLocalJavaWorkspace.class);
38
39 // Exposes commands meta-info
40 public final static String ID = DistPlugin.ID + ".createLocalJavaWorkspace";
41 public final static String DEFAULT_LABEL = "Create local Java workspace...";
42 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
43 .getImageDescriptor("icons/addItem.gif");
44
45 // Parameters
46 public final static String PARAM_WORKSPACE_PREFIX = "workspacePrefix";
47
48 /* DEPENDENCY INJECTION */
49 private JavaRepoManager javaRepoManager;
50
51 public Object execute(ExecutionEvent event) throws ExecutionException {
52
53 String prefix = event.getParameter(PARAM_WORKSPACE_PREFIX);
54 // TODO : add an input validator
55 InputDialog inputDialog = new InputDialog(HandlerUtil
56 .getActiveWorkbenchWindow(event).getShell(), "Workspace name?",
57 "Choose a name for the workspace to create",
58 prefix == null ? "" : prefix + "-", null);
59 int result = inputDialog.open();
60
61 String enteredName = inputDialog.getValue();
62 final String legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXZY0123456789_";
63 char[] arr = enteredName.toUpperCase().toCharArray();
64 int count = 0;
65 for (int i = 0; i < arr.length; i++) {
66 if (legalChars.indexOf(arr[i]) == -1)
67 count = count + 7;
68 else
69 count++;
70 }
71
72 if (count > 60) {
73 ErrorFeedback.show("Workspace name '" + enteredName
74 + "' is too long or contains"
75 + " too many special characters such as '.' or '-'.");
76 return null;
77 }
78
79 String workspaceName = enteredName;
80 // Canceled by user
81 if (result == Dialog.CANCEL || workspaceName == null
82 || "".equals(workspaceName.trim()))
83 return null;
84
85 // FIXME will throw an exception if this workspace name is already used.
86 javaRepoManager.createWorkspace(workspaceName);
87
88 CommandHelpers.callCommand(RefreshDistributionsView.ID);
89 if (log.isTraceEnabled())
90 log.trace("WORKSPACE " + workspaceName + " CREATED");
91
92 return null;
93 }
94
95 /* DEPENDENCY INJECTION */
96 public void setJavaRepoManager(JavaRepoManager javaRepoManager) {
97 this.javaRepoManager = javaRepoManager;
98 }
99 }