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.workbench.internal.contributions;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.ui.IWorkbenchWindow;
17 import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
18 import org.simantics.Simantics;
19 import org.simantics.db.management.ISessionContext;
20 import org.simantics.db.management.ISessionContextChangedListener;
21 import org.simantics.db.management.ISessionContextProvider;
22 import org.simantics.db.management.SessionContextChangedEvent;
23 import org.simantics.ui.SimanticsUI;
24 import org.simantics.workbench.internal.Activator;
28 * @author Tuukka Lehtonen
30 public class GraphRequestStatusContribution extends WorkbenchWindowControlContribution implements ISessionContextChangedListener {
32 GraphRequestStatusTrim trim;
33 ISessionContextProvider contextProvider;
36 public String getId() {
37 return "org.simantics.workbench.db.monitor";
41 protected Control createControl(Composite parent) {
42 IWorkbenchWindow window = getWorkbenchWindow();
43 contextProvider = SimanticsUI.getSessionContextProvider(window);
44 contextProvider.addContextChangedListener(this);
46 trim = new GraphRequestStatusTrim(parent, Activator.getDefault().getPreferenceStore());
47 ISessionContext ctx = Simantics.getSessionContext();
49 trim.attachToSession(ctx.getSession());
55 public void dispose() {
56 contextProvider.removeContextChangedListener(this);
62 public void sessionContextChanged(SessionContextChangedEvent event) {
63 // System.out.println("session changed for '" + event.getHandle() + "' from '" + event.getOldValue() + "' to '" + event.getNewValue() + "'");
64 GraphRequestStatusTrim trim = this.trim;
66 ISessionContext ctx = event.getNewValue();
67 trim.attachToSession((ctx != null) ? ctx.getSession() : null);