]>
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/CreateWorkspace.java
86cf1926b5f267446c36bff05df4b871f5489fc7
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 javax
.jcr
.Repository
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.Session
;
21 import javax
.jcr
.security
.Privilege
;
23 import org
.apache
.commons
.logging
.Log
;
24 import org
.apache
.commons
.logging
.LogFactory
;
25 import org
.argeo
.ArgeoException
;
26 import org
.argeo
.jcr
.JcrUtils
;
27 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
28 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
29 import org
.eclipse
.core
.commands
.AbstractHandler
;
30 import org
.eclipse
.core
.commands
.ExecutionEvent
;
31 import org
.eclipse
.core
.commands
.ExecutionException
;
32 import org
.eclipse
.jface
.dialogs
.Dialog
;
33 import org
.eclipse
.jface
.dialogs
.InputDialog
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
37 * Create a new empty workspace in the current repository.
40 public class CreateWorkspace
extends AbstractHandler
{
41 private static final Log log
= LogFactory
.getLog(CreateWorkspace
.class);
42 public final static String ID
= DistPlugin
.ID
+ ".createWorkspace";
43 public final static String DEFAULT_LABEL
= "Create new workspace";
44 public final static String DEFAULT_ICON_PATH
= "icons/addItem.gif";
46 private String slcRole
= "ROLE_SLC";
48 /* DEPENDENCY INJECTION */
49 private Repository repository
;
51 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
52 IWorkbenchWindow iww
= DistPlugin
.getDefault().getWorkbench()
53 .getActiveWorkbenchWindow();
54 // TODO : add an input validator
55 InputDialog inputDialog
= new InputDialog(iww
.getShell(),
56 "New workspace", "Choose a name for the workspace to create",
58 int result
= inputDialog
.open();
61 if (result
== Dialog
.CANCEL
)
64 String workspaceName
= inputDialog
.getValue();
65 Session session
= null;
67 session
= repository
.login();
68 session
.getWorkspace().createWorkspace(workspaceName
);
69 JcrUtils
.logoutQuietly(session
);
71 session
= repository
.login(workspaceName
);
72 JcrUtils
.addPrivilege(session
, "/", slcRole
, Privilege
.JCR_ALL
);
73 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
74 } catch (RepositoryException re
) {
75 throw new ArgeoException(
76 "Unexpected error while creating the new workspace.", re
);
78 JcrUtils
.logoutQuietly(session
);
80 if (log
.isTraceEnabled())
81 log
.trace("WORKSPACE " + workspaceName
+ " CREATED");
85 /* DEPENDENCY INJECTION */
86 public void setRepository(Repository repository
) {
87 this.repository
= repository
;
90 public void setSlcRole(String slcRole
) {
91 this.slcRole
= slcRole
;