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 java
.util
.Iterator
;
20 import javax
.jcr
.Credentials
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.Repository
;
23 import javax
.jcr
.RepositoryException
;
25 import org
.argeo
.slc
.SlcException
;
26 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
27 import org
.argeo
.slc
.client
.ui
.dist
.model
.ModularDistBaseElem
;
28 import org
.argeo
.slc
.client
.ui
.dist
.model
.WorkspaceElem
;
29 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
30 import org
.argeo
.slc
.client
.ui
.dist
.wizards
.GenerateBinariesWizard
;
31 import org
.eclipse
.core
.commands
.AbstractHandler
;
32 import org
.eclipse
.core
.commands
.ExecutionEvent
;
33 import org
.eclipse
.core
.commands
.ExecutionException
;
34 import org
.eclipse
.jface
.dialogs
.Dialog
;
35 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
36 import org
.eclipse
.jface
.viewers
.ISelection
;
37 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
38 import org
.eclipse
.jface
.wizard
.WizardDialog
;
39 import org
.eclipse
.ui
.IViewPart
;
40 import org
.eclipse
.ui
.IWorkbenchPart
;
41 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
44 * Open a {@code GenerateBinariesWizard} wizard for the selected node
46 public class OpenGenerateBinariesWizard
extends AbstractHandler
{
47 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
49 public final static String ID
= DistPlugin
.ID
50 + ".openGenerateBinariesWizard";
51 public final static String DEFAULT_LABEL
= "Generate Aether Index";
52 public final static ImageDescriptor DEFAULT_ICON
= null;
54 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
55 IWorkbenchPart activePart
= DistPlugin
.getDefault().getWorkbench()
56 .getActiveWorkbenchWindow().getActivePage().getActivePart();
58 if (activePart
instanceof IViewPart
) {
59 ISelection selector
= ((IViewPart
) activePart
).getViewSite()
60 .getSelectionProvider().getSelection();
61 if (selector
!= null && selector
instanceof IStructuredSelection
) {
62 Iterator
<?
> it
= ((IStructuredSelection
) selector
).iterator();
63 Object element
= it
.next();
64 if (element
instanceof ModularDistBaseElem
) {
65 ModularDistBaseElem elem
= (ModularDistBaseElem
) element
;
66 // Session newSession = null;
68 Node cBase
= elem
.getCategoryBase();
69 String catBasePath
= cBase
.getPath();
70 // newSession = ((WorkspaceElem) elem.getParent())
73 String wkspName
= ((WorkspaceElem
) elem
.getParent())
75 Repository repository
= ((WorkspaceElem
) elem
76 .getParent()).getRepoElem().getRepository();
77 Credentials credentials
= ((WorkspaceElem
) elem
78 .getParent()).getRepoElem().getCredentials();
80 GenerateBinariesWizard wizard
= new GenerateBinariesWizard(
81 repository
, credentials
, wkspName
, catBasePath
);
83 WizardDialog dialog
= new WizardDialog(
84 HandlerUtil
.getActiveShell(event
), wizard
);
85 int result
= dialog
.open();
87 if (result
== Dialog
.OK
)
89 .callCommand(RefreshDistributionsView
.ID
);
90 } catch (RepositoryException re
) {
91 throw new SlcException(
92 "Unable to duplicate session for node " + elem
,
95 // JcrUtils.logoutQuietly(newSession);