]> 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/OpenGenerateBinariesWizard.java
Work on index policies.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / OpenGenerateBinariesWizard.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 java.util.Iterator;
19
20 import javax.jcr.Credentials;
21 import javax.jcr.Node;
22 import javax.jcr.Repository;
23 import javax.jcr.RepositoryException;
24
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;
42
43 /**
44 * Open a {@code GenerateBinariesWizard} wizard for the selected node
45 */
46 public class OpenGenerateBinariesWizard extends AbstractHandler {
47 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
48
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;
53
54 public Object execute(ExecutionEvent event) throws ExecutionException {
55 IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench()
56 .getActiveWorkbenchWindow().getActivePage().getActivePart();
57
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;
67 try {
68 Node cBase = elem.getCategoryBase();
69 String catBasePath = cBase.getPath();
70 // newSession = ((WorkspaceElem) elem.getParent())
71 // .getNewSession();
72
73 String wkspName = ((WorkspaceElem) elem.getParent())
74 .getWorkspaceName();
75 Repository repository = ((WorkspaceElem) elem
76 .getParent()).getRepoElem().getRepository();
77 Credentials credentials = ((WorkspaceElem) elem
78 .getParent()).getRepoElem().getCredentials();
79
80 GenerateBinariesWizard wizard = new GenerateBinariesWizard(
81 repository, credentials, wkspName, catBasePath);
82
83 WizardDialog dialog = new WizardDialog(
84 HandlerUtil.getActiveShell(event), wizard);
85 int result = dialog.open();
86
87 if (result == Dialog.OK)
88 CommandHelpers
89 .callCommand(RefreshDistributionsView.ID);
90 } catch (RepositoryException re) {
91 throw new SlcException(
92 "Unable to duplicate session for node " + elem,
93 re);
94 // } finally {
95 // JcrUtils.logoutQuietly(newSession);
96 }
97 }
98
99 }
100 }
101 return null;
102 }
103 }