]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/GraphRequestStatusContribution.java
1d1279a062fde2a845dcbb7cc5a7531dc4ece33e
[simantics/platform.git] / bundles / org.simantics.workbench / src / org / simantics / workbench / internal / contributions / GraphRequestStatusContribution.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.workbench.internal.contributions;
13
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.db.management.ISessionContext;
19 import org.simantics.db.management.ISessionContextChangedListener;
20 import org.simantics.db.management.ISessionContextProvider;
21 import org.simantics.db.management.SessionContextChangedEvent;
22 import org.simantics.ui.SimanticsUI;
23 import org.simantics.workbench.internal.Activator;
24
25
26 /**
27  * @author Tuukka Lehtonen
28  */
29 public class GraphRequestStatusContribution extends WorkbenchWindowControlContribution implements ISessionContextChangedListener {
30
31     GraphRequestStatusTrim  trim;
32     ISessionContextProvider contextProvider;
33
34     @Override
35     public String getId() {
36         return "org.simantics.workbench.db.monitor";
37     }
38
39     @Override
40     protected Control createControl(Composite parent) {
41         IWorkbenchWindow window = getWorkbenchWindow();
42         contextProvider = SimanticsUI.getSessionContextProvider(window);
43         contextProvider.addContextChangedListener(this);
44
45         trim = new GraphRequestStatusTrim(parent, Activator.getDefault().getPreferenceStore());
46         ISessionContext ctx = SimanticsUI.getSessionContext();
47         if (ctx != null) {
48             trim.attachToSession(ctx.getSession());
49         }
50         return trim;
51     }
52
53     @Override
54     public void dispose() {
55         contextProvider.removeContextChangedListener(this);
56         trim = null;
57         super.dispose();
58     }
59
60     @Override
61     public void sessionContextChanged(SessionContextChangedEvent event) {
62 //        System.out.println("session changed for '" + event.getHandle() + "' from '" + event.getOldValue() + "' to '" + event.getNewValue() + "'");
63         GraphRequestStatusTrim trim = this.trim;
64         if (trim != null) {
65             ISessionContext ctx = event.getNewValue();
66             trim.attachToSession((ctx != null) ? ctx.getSession() : null);
67         }
68     }
69
70 }