]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/view/ChangeInformationView.java
Improved Copy Visible Data usability in time series chart editor
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / view / ChangeInformationView.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  *     Semantum Oy - index based searching and graph manipulation (#4255)
12  *******************************************************************************/
13 package org.simantics.modeling.ui.view;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.ui.IActionBars;
21 import org.eclipse.ui.part.ViewPart;
22 import org.simantics.Simantics;
23 import org.simantics.db.Resource;
24 import org.simantics.db.Session;
25 import org.simantics.db.exception.DatabaseException;
26 import org.simantics.ui.SimanticsUI;
27 import org.simantics.ui.workbench.ResourceInput;
28 import org.simantics.utils.ui.BundleUtils;
29 import org.simantics.utils.ui.ErrorLogger;
30 import org.simantics.utils.ui.LayoutUtils;
31
32 public class ChangeInformationView extends ViewPart {
33
34         public static final String VIEW_ID = "org.simantics.modeling.changeInformation";
35
36         private ResourceInput input;
37
38         private Session session;
39
40         private ChangeInformationComposite composite;
41
42         private IAction refreshAction;
43
44         @Override
45         public void createPartControl(Composite parent) {
46
47                 session = Simantics.getSession();
48
49                 // Initialize input
50                 String sid = getViewSite().getSecondaryId();
51                 Resource r = null;
52                 if (sid != null) {
53                         input = ResourceInput.unmarshall(sid);
54                         try {
55                                 r = input.toResource(session);
56                         } catch (DatabaseException e) {
57                                 ErrorLogger.defaultLogError(e);
58                         }
59                 }
60
61                 // Create UI
62                 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
63                 composite = new ChangeInformationComposite(parent, SWT.NONE, session, r, getSite());
64                 composite.defaultInitializeUI();
65
66                 // Contribute actions
67                 makeActions();
68                 contributeActions(getViewSite().getActionBars());
69
70         }
71
72         private void makeActions() {
73                 refreshAction = new RefreshAction();
74         }
75
76          private void contributeActions(IActionBars actionBars) {
77                  IToolBarManager toolBar = actionBars.getToolBarManager();
78                  toolBar.add(refreshAction);
79          }
80         
81         @Override
82         public void setFocus() {
83                 if (composite != null)
84                         composite.setFocus();
85         }
86
87         class RefreshAction extends Action {
88                 public RefreshAction() {
89                         super("Refresh",
90                                         BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID,
91                                                         "icons/refresh.gif"));
92                         setToolTipText("Refresh");
93                 }
94                 @Override
95                 public void run() {
96                         composite.refresh();
97                 }
98         }
99
100 }