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