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