]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/GraphRequestStatusContribution.java
Remove usage of deprecated SimanticsUI-methods
[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.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;
25
26
27 /**
28  * @author Tuukka Lehtonen
29  */
30 public class GraphRequestStatusContribution extends WorkbenchWindowControlContribution implements ISessionContextChangedListener {
31
32     GraphRequestStatusTrim  trim;
33     ISessionContextProvider contextProvider;
34
35     @Override
36     public String getId() {
37         return "org.simantics.workbench.db.monitor";
38     }
39
40     @Override
41     protected Control createControl(Composite parent) {
42         IWorkbenchWindow window = getWorkbenchWindow();
43         contextProvider = SimanticsUI.getSessionContextProvider(window);
44         contextProvider.addContextChangedListener(this);
45
46         trim = new GraphRequestStatusTrim(parent, Activator.getDefault().getPreferenceStore());
47         ISessionContext ctx = Simantics.getSessionContext();
48         if (ctx != null) {
49             trim.attachToSession(ctx.getSession());
50         }
51         return trim;
52     }
53
54     @Override
55     public void dispose() {
56         contextProvider.removeContextChangedListener(this);
57         trim = null;
58         super.dispose();
59     }
60
61     @Override
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;
65         if (trim != null) {
66             ISessionContext ctx = event.getNewValue();
67             trim.attachToSession((ctx != null) ? ctx.getSession() : null);
68         }
69     }
70
71 }