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
.views
;
18 import java
.util
.HashMap
;
21 import javax
.jcr
.Repository
;
22 import javax
.jcr
.RepositoryException
;
24 import org
.argeo
.eclipse
.ui
.TreeParent
;
25 import org
.argeo
.eclipse
.ui
.utils
.CommandUtils
;
26 import org
.argeo
.jcr
.ArgeoNames
;
27 import org
.argeo
.slc
.SlcException
;
28 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
29 import org
.argeo
.slc
.client
.ui
.dist
.commands
.CopyLocalJavaWorkspace
;
30 import org
.argeo
.slc
.client
.ui
.dist
.commands
.CopyWorkspace
;
31 import org
.argeo
.slc
.client
.ui
.dist
.commands
.CreateLocalJavaWorkspace
;
32 import org
.argeo
.slc
.client
.ui
.dist
.commands
.CreateWorkspace
;
33 import org
.argeo
.slc
.client
.ui
.dist
.commands
.DeleteWorkspace
;
34 import org
.argeo
.slc
.client
.ui
.dist
.commands
.DisplayRepoInformation
;
35 import org
.argeo
.slc
.client
.ui
.dist
.commands
.Fetch
;
36 import org
.argeo
.slc
.client
.ui
.dist
.commands
.NormalizeDistribution
;
37 import org
.argeo
.slc
.client
.ui
.dist
.commands
.NormalizeWorkspace
;
38 import org
.argeo
.slc
.client
.ui
.dist
.commands
.OpenGenerateBinariesWizard
;
39 import org
.argeo
.slc
.client
.ui
.dist
.commands
.PublishWorkspace
;
40 import org
.argeo
.slc
.client
.ui
.dist
.commands
.RegisterRepository
;
41 import org
.argeo
.slc
.client
.ui
.dist
.commands
.RunInOsgi
;
42 import org
.argeo
.slc
.client
.ui
.dist
.commands
.UnregisterRemoteRepo
;
43 import org
.argeo
.slc
.client
.ui
.dist
.controllers
.DistTreeComparator
;
44 import org
.argeo
.slc
.client
.ui
.dist
.controllers
.DistTreeComparer
;
45 import org
.argeo
.slc
.client
.ui
.dist
.controllers
.DistTreeContentProvider
;
46 import org
.argeo
.slc
.client
.ui
.dist
.controllers
.DistTreeDoubleClickListener
;
47 import org
.argeo
.slc
.client
.ui
.dist
.controllers
.DistTreeLabelProvider
;
48 import org
.argeo
.slc
.client
.ui
.dist
.model
.DistParentElem
;
49 import org
.argeo
.slc
.client
.ui
.dist
.model
.ModularDistVersionBaseElem
;
50 import org
.argeo
.slc
.client
.ui
.dist
.model
.RepoElem
;
51 import org
.argeo
.slc
.client
.ui
.dist
.model
.WkspGroupElem
;
52 import org
.argeo
.slc
.client
.ui
.dist
.model
.WorkspaceElem
;
53 import org
.argeo
.slc
.jcr
.SlcNames
;
54 import org
.eclipse
.jface
.action
.IContributionItem
;
55 import org
.eclipse
.jface
.action
.IMenuListener
;
56 import org
.eclipse
.jface
.action
.IMenuManager
;
57 import org
.eclipse
.jface
.action
.MenuManager
;
58 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
59 import org
.eclipse
.jface
.viewers
.TreeViewer
;
60 import org
.eclipse
.jface
.viewers
.TreeViewerColumn
;
61 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
62 import org
.eclipse
.swt
.SWT
;
63 import org
.eclipse
.swt
.widgets
.Composite
;
64 import org
.eclipse
.swt
.widgets
.Menu
;
65 import org
.eclipse
.swt
.widgets
.Tree
;
66 import org
.eclipse
.ui
.IWorkbenchWindow
;
67 import org
.eclipse
.ui
.part
.ViewPart
;
70 * Browse, manipulate and manage distributions across multiple repositories
71 * (like fetch, merge, publish, etc.).
73 public class DistributionsView
extends ViewPart
implements SlcNames
, ArgeoNames
{
74 // private final static Log log =
75 // LogFactory.getLog(DistributionsView.class);
77 public final static String ID
= DistPlugin
.ID
+ ".distributionsView";
79 /* DEPENDENCY INJECTION */
80 private Repository nodeRepository
;
81 private DistTreeContentProvider treeContentProvider
;
83 private TreeViewer viewer
;
86 public void createPartControl(Composite parent
) {
87 // Define the TableViewer
88 viewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
89 | SWT
.FULL_SELECTION
| SWT
.BORDER
);
91 TreeViewerColumn col
= new TreeViewerColumn(viewer
, SWT
.NONE
);
92 col
.getColumn().setWidth(400);
93 col
.setLabelProvider(new DistTreeLabelProvider());
95 final Tree tree
= viewer
.getTree();
96 tree
.setHeaderVisible(false);
97 tree
.setLinesVisible(false);
99 // viewer.setContentProvider(new DistTreeContentProvider());
100 viewer
.setContentProvider(treeContentProvider
);
101 viewer
.addDoubleClickListener(new DistTreeDoubleClickListener(viewer
));
102 viewer
.setComparer(new DistTreeComparer());
104 viewer
.setComparator(new DistTreeComparator());
106 @SuppressWarnings("unused")
107 ViewerComparator vc
= viewer
.getComparator();
109 // Enable retrieving current tree selected items from outside the view
110 getSite().setSelectionProvider(viewer
);
112 MenuManager menuManager
= new MenuManager();
113 Menu menu
= menuManager
.createContextMenu(viewer
.getTree());
114 menuManager
.addMenuListener(new IMenuListener() {
115 public void menuAboutToShow(IMenuManager manager
) {
116 contextMenuAboutToShow(manager
);
119 viewer
.getTree().setMenu(menu
);
120 getSite().registerContextMenu(menuManager
, viewer
);
126 /** Programatically configure the context menu */
127 protected void contextMenuAboutToShow(IMenuManager menuManager
) {
128 IWorkbenchWindow window
= DistPlugin
.getDefault().getWorkbench()
129 .getActiveWorkbenchWindow();
131 // Most of the implemented commands support only one selected
133 boolean singleElement
= ((IStructuredSelection
) viewer
.getSelection())
135 // Get Current selected item :
136 Object firstElement
= ((IStructuredSelection
) viewer
.getSelection())
141 if (firstElement
instanceof TreeParent
142 || firstElement
instanceof DistParentElem
) {
144 String targetRepoPath
= null, workspaceName
= null, workspacePrefix
= null;
145 String modularDistBasePath
= null;
146 // String targetRepoUri = null;
147 // Build conditions depending on element type
148 boolean isDistribElem
= false, isModularDistVersionBaseElem
= false, isRepoElem
= false, isDistribGroupElem
= false;
149 boolean isLocal
= false, isReadOnly
= true;
153 if (firstElement
instanceof RepoElem
) {
154 re
= (RepoElem
) firstElement
;
156 isLocal
= re
.inHome();
157 isReadOnly
= re
.isReadOnly();
158 } else if (firstElement
instanceof WkspGroupElem
) {
159 WkspGroupElem wge
= (WkspGroupElem
) firstElement
;
160 isReadOnly
= wge
.isReadOnly();
161 isDistribGroupElem
= true;
162 re
= (RepoElem
) wge
.getParent();
163 workspacePrefix
= wge
.getName();
164 } else if (firstElement
instanceof WorkspaceElem
) {
165 WorkspaceElem we
= (WorkspaceElem
) firstElement
;
166 re
= we
.getRepoElem();
167 isDistribElem
= true;
168 isReadOnly
= we
.isReadOnly();
169 workspaceName
= we
.getWorkspaceName();
170 isLocal
= we
.inHome();
171 } else if (firstElement
instanceof ModularDistVersionBaseElem
) {
172 ModularDistVersionBaseElem mdbe
= (ModularDistVersionBaseElem
) firstElement
;
173 isModularDistVersionBaseElem
= true;
174 re
= mdbe
.getWkspElem().getRepoElem();
175 isLocal
= re
.inHome();
176 isReadOnly
= re
.isReadOnly();
177 workspaceName
= mdbe
.getWkspElem().getWorkspaceName();
178 modularDistBasePath
= mdbe
.getModularDistBase().getPath();
182 targetRepoPath
= re
.getRepoNodePath();
186 CommandUtils
.refreshCommand(menuManager
, window
,
187 DisplayRepoInformation
.ID
,
188 DisplayRepoInformation
.DEFAULT_LABEL
,
189 DisplayRepoInformation
.DEFAULT_ICON
, isRepoElem
193 Map
<String
, String
> params
= new HashMap
<String
, String
>();
194 params
.put(CreateWorkspace
.PARAM_TARGET_REPO_PATH
,
196 params
.put(CreateWorkspace
.PARAM_WORKSPACE_PREFIX
,
198 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
199 CreateWorkspace
.ID
, CreateWorkspace
.DEFAULT_LABEL
,
200 CreateWorkspace
.DEFAULT_ICON
,
201 (isRepoElem
|| isDistribGroupElem
) && singleElement
202 && !isReadOnly
&& !isLocal
, params
);
204 // TODO Manage the case where it is not a java workspace
205 params
= new HashMap
<String
, String
>();
206 params
.put(CreateLocalJavaWorkspace
.PARAM_WORKSPACE_PREFIX
,
208 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
209 CreateLocalJavaWorkspace
.ID
,
210 CreateLocalJavaWorkspace
.DEFAULT_LABEL
,
211 CreateLocalJavaWorkspace
.DEFAULT_ICON
,
212 (isRepoElem
|| isDistribGroupElem
) && singleElement
213 && !isReadOnly
&& isLocal
, params
);
215 // Register a remote repository
216 CommandUtils
.refreshCommand(menuManager
, window
,
217 RegisterRepository
.ID
,
218 RegisterRepository
.DEFAULT_LABEL
,
219 RegisterRepository
.DEFAULT_ICON
, isRepoElem
222 // Unregister a remote repository
223 params
= new HashMap
<String
, String
>();
224 params
.put(UnregisterRemoteRepo
.PARAM_REPO_PATH
, targetRepoPath
);
225 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
226 UnregisterRemoteRepo
.ID
,
227 UnregisterRemoteRepo
.DEFAULT_LABEL
,
228 UnregisterRemoteRepo
.DEFAULT_ICON
, isRepoElem
229 && !isLocal
&& singleElement
, params
);
232 params
= new HashMap
<String
, String
>();
233 params
.put(Fetch
.PARAM_TARGET_REPO_PATH
, targetRepoPath
);
234 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
235 Fetch
.ID
, Fetch
.DEFAULT_LABEL
, Fetch
.DEFAULT_ICON
,
236 isRepoElem
&& isLocal
&& singleElement
&& !isReadOnly
,
239 // Normalize workspace
240 params
= new HashMap
<String
, String
>();
241 params
.put(NormalizeWorkspace
.PARAM_TARGET_REPO_PATH
,
243 params
.put(NormalizeWorkspace
.PARAM_WORKSPACE_NAME
,
246 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
247 NormalizeWorkspace
.ID
, "Normalize...",
248 NormalizeWorkspace
.DEFAULT_ICON
, isDistribElem
249 && singleElement
&& !isReadOnly
, params
);
252 params
= new HashMap
<String
, String
>();
253 params
.put(CopyWorkspace
.PARAM_TARGET_REPO_PATH
, targetRepoPath
);
254 params
.put(CopyWorkspace
.PARAM_SOURCE_WORKSPACE_NAME
,
256 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
257 CopyWorkspace
.ID
, CopyWorkspace
.DEFAULT_LABEL
,
258 CopyWorkspace
.DEFAULT_ICON
, isDistribElem
259 && singleElement
&& !isLocal
, params
);
261 params
= new HashMap
<String
, String
>();
262 params
.put(CopyLocalJavaWorkspace
.PARAM_SOURCE_WORKSPACE_NAME
,
264 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
265 CopyLocalJavaWorkspace
.ID
,
266 CopyLocalJavaWorkspace
.DEFAULT_LABEL
,
267 CopyLocalJavaWorkspace
.DEFAULT_ICON
, isDistribElem
268 && singleElement
&& isLocal
, params
);
271 params
= new HashMap
<String
, String
>();
272 params
.put(DeleteWorkspace
.PARAM_TARGET_REPO_PATH
,
274 params
.put(DeleteWorkspace
.PARAM_WORKSPACE_NAME
, workspaceName
);
275 CommandUtils
.refreshParametrizedCommand(menuManager
, window
,
276 DeleteWorkspace
.ID
, DeleteWorkspace
.DEFAULT_LABEL
,
277 DeleteWorkspace
.DEFAULT_ICON
, isDistribElem
278 && singleElement
&& !isReadOnly
, params
);
281 MenuManager submenu
= new MenuManager("Advanced", DistPlugin
.ID
282 + ".advancedSubmenu");
283 IContributionItem ici
= menuManager
.find(DistPlugin
.ID
284 + ".advancedSubmenu");
286 menuManager
.remove(ici
);
289 params
= new HashMap
<String
, String
>();
290 params
.put(PublishWorkspace
.PARAM_TARGET_REPO_PATH
,
292 params
.put(PublishWorkspace
.PARAM_WORKSPACE_NAME
, workspaceName
);
293 CommandUtils
.refreshParametrizedCommand(submenu
, window
,
294 PublishWorkspace
.ID
, PublishWorkspace
.DEFAULT_LABEL
,
295 PublishWorkspace
.DEFAULT_ICON
, isDistribElem
296 && singleElement
&& !isReadOnly
, params
);
298 // Normalize distribution (Legacy)
299 params
= new HashMap
<String
, String
>();
300 params
.put(NormalizeDistribution
.PARAM_TARGET_REPO_PATH
,
302 params
.put(NormalizeDistribution
.PARAM_WORKSPACE_NAME
,
304 CommandUtils
.refreshParametrizedCommand(submenu
, window
,
305 NormalizeDistribution
.ID
,
306 NormalizeDistribution
.DEFAULT_LABEL
,
307 NormalizeDistribution
.DEFAULT_ICON
, isDistribElem
308 && singleElement
&& !isReadOnly
, params
);
311 params
= new HashMap
<String
, String
>();
312 params
.put(RunInOsgi
.PARAM_WORKSPACE_NAME
, workspaceName
);
313 CommandUtils
.refreshParametrizedCommand(submenu
, window
,
314 RunInOsgi
.ID
, RunInOsgi
.DEFAULT_LABEL
,
315 RunInOsgi
.DEFAULT_ICON
, isDistribElem
&& singleElement
318 // Open generate binaries
319 params
= new HashMap
<String
, String
>();
320 params
.put(OpenGenerateBinariesWizard
.PARAM_REPO_NODE_PATH
,
322 params
.put(OpenGenerateBinariesWizard
.PARAM_MODULE_PATH
,
323 modularDistBasePath
);
324 params
.put(OpenGenerateBinariesWizard
.PARAM_WORKSPACE_NAME
,
327 CommandUtils
.refreshParametrizedCommand(submenu
, window
,
328 OpenGenerateBinariesWizard
.ID
,
329 OpenGenerateBinariesWizard
.DEFAULT_LABEL
,
330 OpenGenerateBinariesWizard
.DEFAULT_ICON
,
331 isModularDistVersionBaseElem
&& !isReadOnly
, params
);
333 if (submenu
.getSize() > 0)
334 menuManager
.add(submenu
);
336 // // Manage workspace authorizations
337 // params = new HashMap<String, String>();
338 // params.put(ManageWorkspaceAuth.PARAM_WORKSPACE_NAME, wsName);
339 // CommandHelpers.refreshParameterizedCommand(menuManager,
341 // ManageWorkspaceAuth.ID, ManageWorkspaceAuth.DEFAULT_LABEL,
342 // ManageWorkspaceAuth.DEFAULT_ICON_PATH, isDistribElem
343 // && singleElement && !isReadOnly, params);
345 } catch (RepositoryException e
) {
346 throw new SlcException("unexpected errror while "
347 + "building context menu for element " + firstElement
, e
);
352 public void setFocus() {
353 viewer
.getTree().setFocus();
357 * Force refresh of the whole view
359 public void refresh() {
360 viewer
.setInput(nodeRepository
);
361 viewer
.expandToLevel(2);
365 * DEPENDENCY INJECTION
367 public void setNodeRepository(Repository repository
) {
368 this.nodeRepository
= repository
;
371 public void setTreeContentProvider(
372 DistTreeContentProvider treeContentProvider
) {
373 this.treeContentProvider
= treeContentProvider
;