Révision 3605

TXM/trunk/org.txm.groovy.rcp/src/org/txm/groovy/ide/rcp/Activator.java (revision 3605)
1
package org.txm.groovy.ide.rcp;
2

  
3
import org.eclipse.ui.plugin.AbstractUIPlugin;
4
import org.osgi.framework.BundleContext;
5

  
6
public class Activator extends AbstractUIPlugin {
7
	
8
	public Activator() {
9
		// TODO Auto-generated constructor stub
10
	}
11
	
12
	@Override
13
	public void start(BundleContext context) throws Exception {
14
		super.start(context);
15
		
16
		System.out.println("DISABLE CONTRIBUTIONS");
17
	}
18
}
0 19

  
TXM/trunk/org.txm.groovy.rcp/src/org/txm/groovy/ide/rcp/views/SampleView.java (revision 3605)
1
package org.txm.groovy.ide.rcp.views;
2

  
3

  
4
import org.eclipse.swt.widgets.Composite;
5
import org.eclipse.ui.part.*;
6
import org.eclipse.jface.viewers.*;
7
import org.eclipse.swt.graphics.Image;
8
import org.eclipse.jface.action.*;
9
import org.eclipse.jface.dialogs.MessageDialog;
10
import org.eclipse.ui.*;
11
import org.eclipse.swt.widgets.Menu;
12
import org.eclipse.swt.SWT;
13

  
14

  
15
/**
16
 * This sample class demonstrates how to plug-in a new
17
 * workbench view. The view shows data obtained from the
18
 * model. The sample creates a dummy model on the fly,
19
 * but a real implementation would connect to the model
20
 * available either in this or another plug-in (e.g. the workspace).
21
 * The view is connected to the model using a content provider.
22
 * <p>
23
 * The view uses a label provider to define how model
24
 * objects should be presented in the view. Each
25
 * view can present the same model objects using
26
 * different labels and icons, if needed. Alternatively,
27
 * a single label provider can be shared between views
28
 * in order to ensure that objects of the same type are
29
 * presented in the same way everywhere.
30
 * <p>
31
 */
32

  
33
public class SampleView extends ViewPart {
34
	
35
	/**
36
	 * The ID of the view as specified by the extension.
37
	 */
38
	public static final String ID = "org.txm.groovy.rcp.views.SampleView";
39
	
40
	private TableViewer viewer;
41
	
42
	private Action action1;
43
	
44
	private Action action2;
45
	
46
	private Action doubleClickAction;
47
	
48
	/*
49
	 * The content provider class is responsible for
50
	 * providing objects to the view. It can wrap
51
	 * existing objects in adapters or simply return
52
	 * objects as-is. These objects may be sensitive
53
	 * to the current input of the view, or ignore
54
	 * it and always show the same content
55
	 * (like Task List, for example).
56
	 */
57
	
58
	class ViewContentProvider implements IStructuredContentProvider {
59
		
60
		public void inputChanged(Viewer v, Object oldInput, Object newInput) {}
61
		
62
		public void dispose() {}
63
		
64
		public Object[] getElements(Object parent) {
65
			return new String[] { "One", "Two", "Three" };
66
		}
67
	}
68
	
69
	class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
70
		
71
		public String getColumnText(Object obj, int index) {
72
			return getText(obj);
73
		}
74
		
75
		public Image getColumnImage(Object obj, int index) {
76
			return getImage(obj);
77
		}
78
		
79
		public Image getImage(Object obj) {
80
			return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
81
		}
82
	}
83
	
84
	class NameSorter extends ViewerSorter {
85
	}
86
	
87
	/**
88
	 * The constructor.
89
	 */
90
	public SampleView() {}
91
	
92
	/**
93
	 * This is a callback that will allow us
94
	 * to create the viewer and initialize it.
95
	 */
96
	public void createPartControl(Composite parent) {
97
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
98
		viewer.setContentProvider(new ViewContentProvider());
99
		viewer.setLabelProvider(new ViewLabelProvider());
100
		viewer.setSorter(new NameSorter());
101
		viewer.setInput(getViewSite());
102
		
103
		// Create the help context id for the viewer's control
104
		PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.txm.groovy.rcp.viewer");
105
		makeActions();
106
		hookContextMenu();
107
		hookDoubleClickAction();
108
		contributeToActionBars();
109
	}
110
	
111
	private void hookContextMenu() {
112
		MenuManager menuMgr = new MenuManager("#PopupMenu");
113
		menuMgr.setRemoveAllWhenShown(true);
114
		menuMgr.addMenuListener(new IMenuListener() {
115
			
116
			public void menuAboutToShow(IMenuManager manager) {
117
				SampleView.this.fillContextMenu(manager);
118
			}
119
		});
120
		Menu menu = menuMgr.createContextMenu(viewer.getControl());
121
		viewer.getControl().setMenu(menu);
122
		getSite().registerContextMenu(menuMgr, viewer);
123
	}
124
	
125
	private void contributeToActionBars() {
126
		IActionBars bars = getViewSite().getActionBars();
127
		fillLocalPullDown(bars.getMenuManager());
128
		fillLocalToolBar(bars.getToolBarManager());
129
	}
130
	
131
	private void fillLocalPullDown(IMenuManager manager) {
132
		manager.add(action1);
133
		manager.add(new Separator());
134
		manager.add(action2);
135
	}
136
	
137
	private void fillContextMenu(IMenuManager manager) {
138
		manager.add(action1);
139
		manager.add(action2);
140
		// Other plug-ins can contribute there actions here
141
		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
142
	}
143
	
144
	private void fillLocalToolBar(IToolBarManager manager) {
145
		manager.add(action1);
146
		manager.add(action2);
147
	}
148
	
149
	private void makeActions() {
150
		action1 = new Action() {
151
			
152
			public void run() {
153
				showMessage("Action 1 executed");
154
			}
155
		};
156
		action1.setText("Action 1");
157
		action1.setToolTipText("Action 1 tooltip");
158
		action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
159
		
160
		action2 = new Action() {
161
			
162
			public void run() {
163
				showMessage("Action 2 executed");
164
			}
165
		};
166
		action2.setText("Action 2");
167
		action2.setToolTipText("Action 2 tooltip");
168
		action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
169
		doubleClickAction = new Action() {
170
			
171
			public void run() {
172
				ISelection selection = viewer.getSelection();
173
				Object obj = ((IStructuredSelection) selection).getFirstElement();
174
				showMessage("Double-click detected on " + obj.toString());
175
			}
176
		};
177
	}
178
	
179
	private void hookDoubleClickAction() {
180
		viewer.addDoubleClickListener(new IDoubleClickListener() {
181
			
182
			public void doubleClick(DoubleClickEvent event) {
183
				doubleClickAction.run();
184
			}
185
		});
186
	}
187
	
188
	private void showMessage(String message) {
189
		MessageDialog.openInformation(
190
				viewer.getControl().getShell(),
191
				"Sample View",
192
				message);
193
	}
194
	
195
	/**
196
	 * Passing the focus request to the viewer's control.
197
	 */
198
	public void setFocus() {
199
		viewer.getControl().setFocus();
200
	}
201
}
0 202

  
TXM/trunk/org.txm.groovy.rcp/plugin.xml (revision 3605)
6 6
         point="org.eclipse.ui.views">
7 7
      <category
8 8
            name="%category.name"
9
            id="org.txm.groovy.rcp">
9
            id="org.txm.groovy.ide.rcp">
10 10
      </category>
11 11
      <view
12 12
            name="%view.name"
13 13
            icon="icons/sample.gif"
14
            category="org.txm.groovy.rcp"
15
            class="org.txm.groovy.rcp.views.SampleView"
16
            id="org.txm.groovy.rcp.views.SampleView">
14
            category="org.txm.groovy.ide.rcp"
15
            class="org.txm.groovy.ide.rcp.views.SampleView"
16
            id="org.txm.groovy.ide.rcp.views.SampleView">
17 17
      </view>
18 18
   </extension>
19 19
   <extension point="org.eclipse.ui.activities">  
......
41 41
               ratio="0.5"
42 42
               relative="org.eclipse.ui.views.ProblemView"
43 43
               relationship="right"
44
               id="org.txm.groovy.rcp.views.SampleView">
44
               id="org.txm.groovy.ide.rcp.views.SampleView">
45 45
         </view>
46 46
      </perspectiveExtension>
47 47
   </extension>
TXM/trunk/org.txm.groovy.rcp/META-INF/MANIFEST.MF (revision 3605)
1 1
Manifest-Version: 1.0
2
Bundle-SymbolicName: org.txm.groovy.rcp;singleton:=true
3
Export-Package: org.txm.groovy.rcp,org.txm.groovy.rcp.views
2
Bundle-SymbolicName: org.txm.groovy.ide.rcp;singleton:=true
3
Export-Package: org.txm.groovy.ide.rcp,
4
 org.txm.groovy.ide.rcp.views
4 5
Bundle-Version: 1.0.0.qualifier
5 6
Bundle-Name: %Bundle-Name
6 7
Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,org.ecli
......
8 9
 ";visibility:=reexport,org.codehaus.groovy.eclipse.ui;bundle-version=
9 10
 "2.9.1";visibility:=reexport
10 11
Bundle-ManifestVersion: 2
11
Bundle-Activator: org.txm.groovy.rcp.Activator
12
Bundle-Activator: org.txm.groovy.ide.rcp.Activator
12 13
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
13 14
Bundle-Vendor: Textometry.org
14 15
Automatic-Module-Name: org.txm.groovy.rcp
TXM/trunk/org.txm.groovy.rcp/.project (revision 3605)
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<projectDescription>
3
	<name>org.txm.groovy.rcp</name>
3
	<name>org.txm.groovy.ide.rcp</name>
4 4
	<comment></comment>
5 5
	<projects>
6 6
	</projects>

Formats disponibles : Unified diff