1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.structural.ui.modelBrowser;
\r
14 import java.util.Collections;
\r
15 import java.util.HashMap;
\r
16 import java.util.Map;
\r
17 import java.util.Set;
\r
19 import org.eclipse.jface.action.Action;
\r
20 import org.eclipse.swt.widgets.Composite;
\r
21 import org.eclipse.ui.ISharedImages;
\r
22 import org.eclipse.ui.PartInitException;
\r
23 import org.eclipse.ui.PlatformUI;
\r
24 import org.simantics.browsing.ui.model.browsecontexts.BrowseContext;
\r
25 import org.simantics.browsing.ui.platform.GraphExplorerView;
\r
26 import org.simantics.browsing.ui.swt.ViewArgumentUtils;
\r
27 import org.simantics.db.UndoContext;
\r
28 import org.simantics.db.common.UndoContextEx;
\r
29 import org.simantics.db.exception.DatabaseException;
\r
30 import org.simantics.structural.ui.Activator;
\r
31 import org.simantics.ui.SimanticsUI;
\r
32 import org.simantics.utils.ui.ExceptionUtils;
\r
33 import org.simantics.utils.ui.workbench.WorkbenchUtils;
\r
35 public class ModelBrowser extends GraphExplorerView {
\r
37 private static final String CONTEXT_MENU_ID = "#GraphExplorerPopup";
\r
38 private static final Set<String> uiContexts = Collections.singleton("org.simantics.modeling.ui.modelBrowser");
\r
39 private static final Set<String> defaultBrowseContexts = Collections.singleton("http://www.simantics.org/Structural-0.0/ModelBrowser");
\r
40 protected UndoContext undoContext = new UndoContextEx("ModelBrowser");
\r
43 protected Set<String> getUiContexts() {
\r
48 protected Set<String> getBrowseContexts() {
\r
49 return defaultBrowseContexts;
\r
53 protected String getContextMenuId() {
\r
54 return CONTEXT_MENU_ID;
\r
57 @SuppressWarnings("rawtypes")
\r
59 public Object getAdapter(Class adapter) {
\r
60 if (adapter == UndoContext.class)
\r
62 return super.getAdapter(adapter);
\r
66 protected void createControls(Composite parent) {
\r
67 // Make sure the resource manager of this plug-in is initialized
\r
68 // properly before using it in this browser.
\r
69 Activator.initializeResourceManager(parent.getDisplay());
\r
71 super.createControls(parent);
\r
72 //IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
\r
73 //toolBar.add(new HomeAction());
\r
76 class HomeAction extends Action {
\r
77 public HomeAction() {
\r
78 super("Home", Action.AS_PUSH_BUTTON);
\r
79 setToolTipText("Navigate to root library");
\r
80 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));
\r
81 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));
\r
85 Map<String, String> args = new HashMap<String, String>();
\r
86 args.put("view", getSite().getId());
\r
87 String argString = ViewArgumentUtils.encodeArguments(args);
\r
89 WorkbenchUtils.showView("org.simantics.browsing.ui.graph.browseDebugger:" + argString);
\r
90 } catch (PartInitException e) {
\r
91 e.printStackTrace();
\r
96 protected static Set<String> loadBrowseContexts(final Set<String> browseContexts) {
\r
98 return BrowseContext.getBrowseContextClosure(SimanticsUI.getSession(), browseContexts);
\r
99 } catch (DatabaseException e) {
\r
100 ExceptionUtils.logAndShowError("Failed to load modeled browse contexts for property page, see exception for details.", e);
\r
101 return browseContexts;
\r