Révision 512
tmp/org.txm.tmp.rcp/plugin.xml (revision 512) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
|
|
5 |
<extension |
|
6 |
point="org.eclipse.ui.views"> |
|
7 |
<category |
|
8 |
name="Sample Category" |
|
9 |
id="org.txm.tmp.rcp"> |
|
10 |
</category> |
|
11 |
<view |
|
12 |
name="Sample View" |
|
13 |
icon="icons/sample.gif" |
|
14 |
category="org.txm.tmp.rcp" |
|
15 |
class="org.txm.tmp.rcp.views.SampleView" |
|
16 |
id="org.txm.tmp.rcp.views.SampleView"> |
|
17 |
</view> |
|
18 |
</extension> |
|
19 |
<extension |
|
20 |
point="org.eclipse.ui.perspectiveExtensions"> |
|
21 |
<perspectiveExtension |
|
22 |
targetID="org.eclipse.jdt.ui.JavaPerspective"> |
|
23 |
<view |
|
24 |
ratio="0.5" |
|
25 |
relative="org.eclipse.ui.views.ProblemView" |
|
26 |
relationship="right" |
|
27 |
id="org.txm.tmp.rcp.views.SampleView"> |
|
28 |
</view> |
|
29 |
</perspectiveExtension> |
|
30 |
</extension> |
|
31 |
<extension |
|
32 |
point="org.eclipse.help.contexts"> |
|
33 |
<contexts |
|
34 |
file="contexts.xml"> |
|
35 |
</contexts> |
|
36 |
</extension> |
|
37 |
|
|
38 |
</plugin> |
|
0 | 39 |
tmp/org.txm.tmp.rcp/.settings/org.eclipse.jdt.core.prefs (revision 512) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate |
|
4 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
|
5 |
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
|
6 |
org.eclipse.jdt.core.compiler.compliance=1.7 |
|
7 |
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
|
8 |
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
|
9 |
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
|
10 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
11 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
12 |
org.eclipse.jdt.core.compiler.source=1.7 |
|
0 | 13 |
tmp/org.txm.tmp.rcp/.classpath (revision 512) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.tmp.rcp/META-INF/MANIFEST.MF (revision 512) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: TMP RCP |
|
4 |
Bundle-SymbolicName: org.txm.tmp.rcp;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Require-Bundle: org.eclipse.core.runtime, |
|
7 |
org.eclipse.ui |
|
8 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
|
0 | 9 |
tmp/org.txm.tmp.rcp/.project (revision 512) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.tmp.rcp</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.tmp.rcp/contexts.xml (revision 512) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<contexts> |
|
3 |
<context id="viewer" title="Sample View"> |
|
4 |
<description>This is the context help for the sample view with a table viewer. It was generated by a PDE template.</description> |
|
5 |
<topic href="/PLUGINS_ROOT/org.eclipse.platform.doc.isv/guide/ua_help_context.htm" label="Context-sensitive help"> |
|
6 |
<enablement> |
|
7 |
<with variable="platform"> |
|
8 |
<test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.platform.doc.isv"/> |
|
9 |
</with> |
|
10 |
</enablement> |
|
11 |
</topic> |
|
12 |
</context> |
|
13 |
</contexts> |
|
0 | 14 |
tmp/org.txm.tmp.rcp/src/org/eclipse/swt/snippets/Snippet36.java (revision 512) | ||
---|---|---|
1 |
package org.eclipse.swt.snippets; |
|
2 |
import org.eclipse.swt.SWT; |
|
3 |
import org.eclipse.swt.graphics.Color; |
|
4 |
import org.eclipse.swt.graphics.GC; |
|
5 |
import org.eclipse.swt.graphics.Image; |
|
6 |
import org.eclipse.swt.graphics.Rectangle; |
|
7 |
import org.eclipse.swt.widgets.Display; |
|
8 |
import org.eclipse.swt.widgets.Shell; |
|
9 |
import org.eclipse.swt.widgets.ToolBar; |
|
10 |
import org.eclipse.swt.widgets.ToolItem; |
|
11 |
|
|
12 |
public class Snippet36 { |
|
13 |
|
|
14 |
public static void main (final String [] args) { |
|
15 |
Display display = new Display(); |
|
16 |
Image image = new Image (display, 16, 16); |
|
17 |
Color color = display.getSystemColor (SWT.COLOR_RED); |
|
18 |
GC gc = new GC (image); |
|
19 |
gc.setBackground (color); |
|
20 |
gc.fillRectangle (image.getBounds ()); |
|
21 |
gc.dispose (); |
|
22 |
Shell shell = new Shell (display); |
|
23 |
ToolBar toolBar = new ToolBar (shell, SWT.FLAT | SWT.BORDER | SWT.RIGHT); |
|
24 |
Rectangle clientArea = shell.getClientArea (); |
|
25 |
toolBar.setLocation (clientArea.x, clientArea.y); |
|
26 |
String[] labels = new String[] {"Short", "Quite a bit longer", "OK"}; |
|
27 |
for (int i=0; i<3; i++) { |
|
28 |
ToolItem item = new ToolItem (toolBar, SWT.PUSH); |
|
29 |
item.setText(labels[i]); |
|
30 |
item.setImage (image); |
|
31 |
} |
|
32 |
toolBar.pack (); |
|
33 |
shell.open (); |
|
34 |
while (!shell.isDisposed()) { |
|
35 |
if (!display.readAndDispatch ()) { |
|
36 |
display.sleep (); |
|
37 |
} |
|
38 |
} |
|
39 |
image.dispose (); |
|
40 |
display.dispose (); |
|
41 |
} |
|
42 |
} |
|
0 | 43 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/Player.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
public class Player { |
|
3 |
private Team team; |
|
4 |
|
|
5 |
private String lastName; |
|
6 |
|
|
7 |
private String firstName; |
|
8 |
|
|
9 |
private float points; |
|
10 |
|
|
11 |
private float rebounds; |
|
12 |
|
|
13 |
private float assists; |
|
14 |
|
|
15 |
/** |
|
16 |
* Constructs an empty Player |
|
17 |
*/ |
|
18 |
public Player() { |
|
19 |
this(null, null, 0.0f, 0.0f, 0.0f); |
|
20 |
} |
|
21 |
|
|
22 |
public String toString() {return firstName+" "+lastName;} |
|
23 |
|
|
24 |
/** |
|
25 |
* Constructs a Player |
|
26 |
* |
|
27 |
* @param firstName |
|
28 |
* the first name |
|
29 |
* @param lastName |
|
30 |
* the last name |
|
31 |
* @param points |
|
32 |
* the points |
|
33 |
* @param rebounds |
|
34 |
* the rebounds |
|
35 |
* @param assists |
|
36 |
* the assists |
|
37 |
*/ |
|
38 |
public Player(String firstName, String lastName, float points, |
|
39 |
float rebounds, float assists) { |
|
40 |
setFirstName(firstName); |
|
41 |
setLastName(lastName); |
|
42 |
setPoints(points); |
|
43 |
setRebounds(rebounds); |
|
44 |
setAssists(assists); |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Sets the team for theo player |
|
49 |
* |
|
50 |
* @param team |
|
51 |
* the team |
|
52 |
*/ |
|
53 |
public void setTeam(Team team) { |
|
54 |
this.team = team; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Gets the assists |
|
59 |
* |
|
60 |
* @return float |
|
61 |
*/ |
|
62 |
public float getAssists() { |
|
63 |
return assists; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Sets the assists |
|
68 |
* |
|
69 |
* @param assists |
|
70 |
* The assists to set. |
|
71 |
*/ |
|
72 |
public void setAssists(float assists) { |
|
73 |
this.assists = assists; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Gets the first name |
|
78 |
* |
|
79 |
* @return String |
|
80 |
*/ |
|
81 |
public String getFirstName() { |
|
82 |
return firstName; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* Sets the first name |
|
87 |
* |
|
88 |
* @param firstName |
|
89 |
* The firstName to set. |
|
90 |
*/ |
|
91 |
public void setFirstName(String firstName) { |
|
92 |
this.firstName = firstName; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Gets the last name |
|
97 |
* |
|
98 |
* @return String |
|
99 |
*/ |
|
100 |
public String getLastName() { |
|
101 |
return lastName; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Sets the last name |
|
106 |
* |
|
107 |
* @param lastName |
|
108 |
* The lastName to set. |
|
109 |
*/ |
|
110 |
public void setLastName(String lastName) { |
|
111 |
this.lastName = lastName; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Gets the points |
|
116 |
* |
|
117 |
* @return float |
|
118 |
*/ |
|
119 |
public float getPoints() { |
|
120 |
return points; |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Sets the points |
|
125 |
* |
|
126 |
* @param points |
|
127 |
* The points to set. |
|
128 |
*/ |
|
129 |
public void setPoints(float points) { |
|
130 |
this.points = points; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Gets the rebounds |
|
135 |
* |
|
136 |
* @return float |
|
137 |
*/ |
|
138 |
public float getRebounds() { |
|
139 |
return rebounds; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* Sets the rebounds |
|
144 |
* |
|
145 |
* @param rebounds |
|
146 |
* The rebounds to set. |
|
147 |
*/ |
|
148 |
public void setRebounds(float rebounds) { |
|
149 |
this.rebounds = rebounds; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Gets the team |
|
154 |
* |
|
155 |
* @return Team |
|
156 |
*/ |
|
157 |
public Team getTeam() { |
|
158 |
return team; |
|
159 |
} |
|
160 |
|
|
161 |
/** |
|
162 |
* Returns whether this player led the team in the specified category |
|
163 |
* |
|
164 |
* @param column |
|
165 |
* the column (category) |
|
166 |
* @return boolean |
|
167 |
*/ |
|
168 |
public boolean ledTeam(int column) { |
|
169 |
return team.led(this, column); |
|
170 |
} |
|
171 |
} |
|
0 | 172 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/PlayerViewerSorter.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
import org.eclipse.jface.viewers.Viewer; |
|
4 |
import org.eclipse.jface.viewers.ViewerSorter; |
|
5 |
|
|
6 |
public class PlayerViewerSorter extends ViewerSorter { |
|
7 |
private static final int ASCENDING = 0; |
|
8 |
|
|
9 |
private static final int DESCENDING = 1; |
|
10 |
|
|
11 |
private int column; |
|
12 |
|
|
13 |
private int direction; |
|
14 |
|
|
15 |
/** |
|
16 |
* Does the sort. If it's a different column from the previous sort, do an |
|
17 |
* ascending sort. If it's the same column as the last sort, toggle the sort |
|
18 |
* direction. |
|
19 |
* |
|
20 |
* @param column |
|
21 |
*/ |
|
22 |
public void doSort(int column) { |
|
23 |
if (column == this.column) { |
|
24 |
// Same column as last sort; toggle the direction |
|
25 |
direction = 1 - direction; |
|
26 |
} else { |
|
27 |
// New column; do an ascending sort |
|
28 |
this.column = column; |
|
29 |
direction = ASCENDING; |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
/** |
|
34 |
* Compares the object for sorting |
|
35 |
*/ |
|
36 |
public int compare(Viewer viewer, Object e1, Object e2) { |
|
37 |
int rc = e1.toString().compareTo(e2.toString()); |
|
38 |
System.out.println("rc="+rc); |
|
39 |
|
|
40 |
// If descending order, flip the direction |
|
41 |
if (direction == DESCENDING) |
|
42 |
rc = -rc; |
|
43 |
|
|
44 |
return rc; |
|
45 |
} |
|
46 |
} |
|
0 | 47 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/PersonLabelProvider.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
|
4 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
5 |
import org.eclipse.swt.graphics.Image; |
|
6 |
|
|
7 |
public class PersonLabelProvider implements ITableLabelProvider { |
|
8 |
/** |
|
9 |
* Returns the image |
|
10 |
* |
|
11 |
* @param element |
|
12 |
* the element |
|
13 |
* @param columnIndex |
|
14 |
* the column index |
|
15 |
* @return Image |
|
16 |
*/ |
|
17 |
public Image getColumnImage(Object element, int columnIndex) { |
|
18 |
return null; |
|
19 |
} |
|
20 |
|
|
21 |
/** |
|
22 |
* Returns the column text |
|
23 |
* |
|
24 |
* @param element |
|
25 |
* the element |
|
26 |
* @param columnIndex |
|
27 |
* the column index |
|
28 |
* @return String |
|
29 |
*/ |
|
30 |
public String getColumnText(Object element, int columnIndex) { |
|
31 |
Person person = (Person) element; |
|
32 |
switch (columnIndex) { |
|
33 |
case 0: |
|
34 |
return person.getName(); |
|
35 |
case 1: |
|
36 |
return Boolean.toString(person.isMale()); |
|
37 |
case 2: |
|
38 |
return AgeRange.INSTANCES[person.getAgeRange().intValue()]; |
|
39 |
case 3: |
|
40 |
return person.getShirtColor().toString(); |
|
41 |
} |
|
42 |
return null; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Adds a listener |
|
47 |
* |
|
48 |
* @param listener |
|
49 |
* the listener |
|
50 |
*/ |
|
51 |
public void addListener(ILabelProviderListener listener) { |
|
52 |
// Ignore it |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Disposes any created resources |
|
57 |
*/ |
|
58 |
public void dispose() { |
|
59 |
// Nothing to dispose |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Returns whether altering this property on this element will affect the |
|
64 |
* label |
|
65 |
* |
|
66 |
* @param element |
|
67 |
* the element |
|
68 |
* @param property |
|
69 |
* the property |
|
70 |
* @return boolean |
|
71 |
*/ |
|
72 |
public boolean isLabelProperty(Object element, String property) { |
|
73 |
return false; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Removes a listener |
|
78 |
* |
|
79 |
* @param listener |
|
80 |
* the listener |
|
81 |
*/ |
|
82 |
public void removeListener(ILabelProviderListener listener) { |
|
83 |
// Ignore |
|
84 |
} |
|
85 |
} |
|
0 | 86 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/PlayerContentProvider.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
4 |
import org.eclipse.jface.viewers.Viewer; |
|
5 |
|
|
6 |
public class PlayerContentProvider implements IStructuredContentProvider { |
|
7 |
|
|
8 |
/** |
|
9 |
* Gets the elements for the table |
|
10 |
* |
|
11 |
* @param arg0 |
|
12 |
* the model |
|
13 |
* @return Object[] |
|
14 |
*/ |
|
15 |
public Object[] getElements(Object arg0) { |
|
16 |
// Returns all the players in the specified team |
|
17 |
return ((Team) arg0).getPlayers().toArray(); |
|
18 |
} |
|
19 |
|
|
20 |
/** |
|
21 |
* Disposes any resources |
|
22 |
*/ |
|
23 |
public void dispose() { |
|
24 |
// We don't create any resources, so we don't dispose any |
|
25 |
} |
|
26 |
|
|
27 |
/** |
|
28 |
* Called when the input changes |
|
29 |
* |
|
30 |
* @param arg0 |
|
31 |
* the parent viewer |
|
32 |
* @param arg1 |
|
33 |
* the old input |
|
34 |
* @param arg2 |
|
35 |
* the new input |
|
36 |
*/ |
|
37 |
public void inputChanged(Viewer arg0, Object arg1, Object arg2) { |
|
38 |
// Nothing to do |
|
39 |
} |
|
40 |
} |
|
0 | 41 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/PlayerConst.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
public class PlayerConst { |
|
3 |
// Column constants |
|
4 |
public static final int COLUMN_FIRST_NAME = 0; |
|
5 |
|
|
6 |
public static final int COLUMN_LAST_NAME = 1; |
|
7 |
|
|
8 |
public static final int COLUMN_POINTS = 2; |
|
9 |
|
|
10 |
public static final int COLUMN_REBOUNDS = 3; |
|
11 |
|
|
12 |
public static final int COLUMN_ASSISTS = 4; |
|
13 |
} |
|
0 | 14 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/PlayerTable.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
|
|
5 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
|
6 |
import org.eclipse.jface.viewers.TableViewer; |
|
7 |
import org.eclipse.jface.viewers.TableViewerColumn; |
|
8 |
import org.eclipse.jface.window.ApplicationWindow; |
|
9 |
import org.eclipse.swt.SWT; |
|
10 |
import org.eclipse.swt.events.SelectionAdapter; |
|
11 |
import org.eclipse.swt.events.SelectionEvent; |
|
12 |
import org.eclipse.swt.events.SelectionListener; |
|
13 |
import org.eclipse.swt.layout.GridData; |
|
14 |
import org.eclipse.swt.layout.GridLayout; |
|
15 |
import org.eclipse.swt.widgets.Button; |
|
16 |
import org.eclipse.swt.widgets.Combo; |
|
17 |
import org.eclipse.swt.widgets.Composite; |
|
18 |
import org.eclipse.swt.widgets.Control; |
|
19 |
import org.eclipse.swt.widgets.Display; |
|
20 |
import org.eclipse.swt.widgets.Event; |
|
21 |
import org.eclipse.swt.widgets.Listener; |
|
22 |
import org.eclipse.swt.widgets.ScrollBar; |
|
23 |
import org.eclipse.swt.widgets.Shell; |
|
24 |
import org.eclipse.swt.widgets.Spinner; |
|
25 |
import org.eclipse.swt.widgets.Table; |
|
26 |
import org.eclipse.swt.widgets.TableColumn; |
|
27 |
|
|
28 |
/** |
|
29 |
* This class demonstrates TableViewers |
|
30 |
*/ |
|
31 |
public class PlayerTable extends ApplicationWindow { |
|
32 |
|
|
33 |
ArrayList<TableColumn> columns = new ArrayList<>(); |
|
34 |
|
|
35 |
// The data model |
|
36 |
private PlayerTableModel model; |
|
37 |
|
|
38 |
// The table viewer |
|
39 |
private TableViewer rightTV; |
|
40 |
|
|
41 |
private Spinner noSpinner; |
|
42 |
|
|
43 |
private TableViewer leftTV; |
|
44 |
|
|
45 |
private Table rightTable, leftTable; |
|
46 |
|
|
47 |
private ScrollBar vBarLeft; |
|
48 |
|
|
49 |
private ScrollBar vBarRight; |
|
50 |
|
|
51 |
/** |
|
52 |
* Constructs a PlayerTable |
|
53 |
*/ |
|
54 |
public PlayerTable() { |
|
55 |
super(null); |
|
56 |
model = new PlayerTableModel(); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Runs the application |
|
61 |
*/ |
|
62 |
public void run() { |
|
63 |
// Don't return from open() until window closes |
|
64 |
setBlockOnOpen(true); |
|
65 |
|
|
66 |
// Open the main window |
|
67 |
open(); |
|
68 |
|
|
69 |
// Dispose the display |
|
70 |
Display.getCurrent().dispose(); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Configures the shell |
|
75 |
* |
|
76 |
* @param shell |
|
77 |
* the shell |
|
78 |
*/ |
|
79 |
protected void configureShell(Shell shell) { |
|
80 |
super.configureShell(shell); |
|
81 |
shell.setSize(400, 400); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Creates the main window's contents |
|
86 |
* |
|
87 |
* @param parent |
|
88 |
* the main window |
|
89 |
* @return Control |
|
90 |
*/ |
|
91 |
protected Control createContents(Composite parent) { |
|
92 |
// Create the composite to hold the controls |
|
93 |
Composite composite = new Composite(parent, SWT.NONE); |
|
94 |
composite.setLayout(new GridLayout(2, false)); |
|
95 |
|
|
96 |
noSpinner = new Spinner(composite, SWT.NONE); |
|
97 |
noSpinner.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
98 |
noSpinner.setMaximum(10); |
|
99 |
noSpinner.setMinimum(0); |
|
100 |
|
|
101 |
Button addColumn = new Button(composite, SWT.PUSH); |
|
102 |
addColumn.setText("add column"); |
|
103 |
addColumn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
104 |
addColumn.addSelectionListener(new SelectionListener() { |
|
105 |
|
|
106 |
@Override |
|
107 |
public void widgetSelected(SelectionEvent e) { |
|
108 |
TableViewerColumn tc = new TableViewerColumn(rightTV, SWT.LEFT, 0); |
|
109 |
columns.add(0, tc.getColumn()); |
|
110 |
tc.getColumn().setText("Col "+noSpinner.getSelection()); |
|
111 |
tc.getColumn().setWidth(100); |
|
112 |
tc.setLabelProvider(new ColumnLabelProvider() { |
|
113 |
|
|
114 |
int i = noSpinner.getSelection(); |
|
115 |
|
|
116 |
@Override |
|
117 |
public String getText(Object element) { |
|
118 |
return ""+element+element+element+element; |
|
119 |
} |
|
120 |
}); |
|
121 |
|
|
122 |
tc.getColumn().addSelectionListener(new SelectionAdapter() { |
|
123 |
public void widgetSelected(SelectionEvent event) { |
|
124 |
((PlayerViewerSorter) rightTV.getSorter()) |
|
125 |
.doSort(PlayerConst.COLUMN_LAST_NAME); |
|
126 |
rightTV.refresh(); |
|
127 |
} |
|
128 |
}); |
|
129 |
|
|
130 |
rightTV.refresh(); |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
135 |
}); |
|
136 |
|
|
137 |
Button killColumn = new Button(composite, SWT.PUSH); |
|
138 |
killColumn.setText("remove last column"); |
|
139 |
killColumn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
140 |
killColumn.addSelectionListener(new SelectionListener() { |
|
141 |
|
|
142 |
@Override |
|
143 |
public void widgetSelected(SelectionEvent e) { |
|
144 |
TableColumn tc = columns.remove(columns.size()-1); |
|
145 |
tc.dispose(); |
|
146 |
} |
|
147 |
|
|
148 |
@Override |
|
149 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
150 |
}); |
|
151 |
|
|
152 |
// Create the combo to hold the team names |
|
153 |
Combo combo = new Combo(composite, SWT.READ_ONLY); |
|
154 |
combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
155 |
|
|
156 |
|
|
157 |
// Create the table viewer to display the players |
|
158 |
leftTable = new Table (composite, SWT.BORDER); |
|
159 |
leftTV = new TableViewer(leftTable); |
|
160 |
leftTable.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
161 |
leftTV.setContentProvider(new PlayerContentProvider()); |
|
162 |
leftTV.setSorter(new PlayerViewerSorter()); |
|
163 |
|
|
164 |
// Add the team names to the combo |
|
165 |
for (int i = 0, n = model.teams.length; i < n; i++) { |
|
166 |
combo.add(model.teams[i].getName()); |
|
167 |
} |
|
168 |
|
|
169 |
// Add a listener to change the tableviewer's input |
|
170 |
combo.addSelectionListener(new SelectionAdapter() { |
|
171 |
public void widgetSelected(SelectionEvent event) { |
|
172 |
update(model.teams[((Combo) event.widget).getSelectionIndex()]); |
|
173 |
} |
|
174 |
}); |
|
175 |
|
|
176 |
// Turn on the header and the lines |
|
177 |
leftTable.setHeaderVisible(true); |
|
178 |
leftTable.setLinesVisible(true); |
|
179 |
|
|
180 |
TableViewerColumn tc = new TableViewerColumn(leftTV, SWT.LEFT, 0); |
|
181 |
columns.add(0, tc.getColumn()); |
|
182 |
tc.getColumn().setText("Col "+noSpinner.getSelection()); |
|
183 |
tc.getColumn().setWidth(100); |
|
184 |
tc.setLabelProvider(new ColumnLabelProvider() { |
|
185 |
|
|
186 |
int i = noSpinner.getSelection(); |
|
187 |
|
|
188 |
@Override |
|
189 |
public String getText(Object element) { |
|
190 |
String l = ""+element; |
|
191 |
if (l.length() < i) return "too long"; |
|
192 |
|
|
193 |
else return l.substring(i); |
|
194 |
|
|
195 |
} |
|
196 |
}); |
|
197 |
|
|
198 |
tc.getColumn().addSelectionListener(new SelectionAdapter() { |
|
199 |
public void widgetSelected(SelectionEvent event) { |
|
200 |
((PlayerViewerSorter) leftTV.getSorter()) |
|
201 |
.doSort(PlayerConst.COLUMN_LAST_NAME); |
|
202 |
leftTV.refresh(); |
|
203 |
} |
|
204 |
}); |
|
205 |
|
|
206 |
// Create the table viewer to display the players |
|
207 |
rightTable = new Table (composite, SWT.BORDER); |
|
208 |
rightTV = new TableViewer(rightTable); |
|
209 |
rightTable.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
210 |
rightTV.setContentProvider(new PlayerContentProvider()); |
|
211 |
rightTV.setSorter(new PlayerViewerSorter()); |
|
212 |
|
|
213 |
|
|
214 |
// Add the team names to the combo |
|
215 |
for (int i = 0, n = model.teams.length; i < n; i++) { |
|
216 |
combo.add(model.teams[i].getName()); |
|
217 |
} |
|
218 |
|
|
219 |
// Add a listener to change the tableviewer's input |
|
220 |
combo.addSelectionListener(new SelectionAdapter() { |
|
221 |
public void widgetSelected(SelectionEvent event) { |
|
222 |
update(model.teams[((Combo) event.widget).getSelectionIndex()]); |
|
223 |
} |
|
224 |
}); |
|
225 |
|
|
226 |
// Turn on the header and the lines |
|
227 |
rightTable.setHeaderVisible(true); |
|
228 |
rightTable.setLinesVisible(true); |
|
229 |
|
|
230 |
leftTable.addSelectionListener(new SelectionListener() { |
|
231 |
@Override |
|
232 |
public void widgetSelected(SelectionEvent e) { |
|
233 |
rightTable.setSelection(leftTable.getSelectionIndex()); |
|
234 |
} |
|
235 |
@Override |
|
236 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
237 |
}); |
|
238 |
vBarLeft = leftTable.getVerticalBar(); |
|
239 |
vBarLeft.addListener(SWT.Selection, new Listener() { |
|
240 |
@Override |
|
241 |
public void handleEvent(Event event) { |
|
242 |
vBarRight.setSelection(vBarLeft.getSelection()); |
|
243 |
} |
|
244 |
}); |
|
245 |
rightTable.addSelectionListener(new SelectionListener() { |
|
246 |
@Override |
|
247 |
public void widgetSelected(SelectionEvent e) { |
|
248 |
leftTable.setSelection(rightTable.getSelectionIndex()); |
|
249 |
} |
|
250 |
@Override |
|
251 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
252 |
}); |
|
253 |
vBarRight = rightTable.getVerticalBar(); |
|
254 |
vBarRight.addListener(SWT.Selection, new Listener() { |
|
255 |
@Override |
|
256 |
public void handleEvent(Event event) { |
|
257 |
vBarLeft.setSelection(vBarRight.getSelection()); |
|
258 |
} |
|
259 |
}); |
|
260 |
|
|
261 |
// Select the first item |
|
262 |
combo.select(0); |
|
263 |
update(model.teams[0]); |
|
264 |
|
|
265 |
return composite; |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* Updates the application with the selected team |
|
270 |
* |
|
271 |
* @param team |
|
272 |
* the team |
|
273 |
*/ |
|
274 |
private void update(Team team) { |
|
275 |
// Update the window's title bar with the new team |
|
276 |
getShell().setText(team.getYear() + " " + team.getName()); |
|
277 |
|
|
278 |
// Set the table viewer's input to the team |
|
279 |
rightTV.setInput(team); |
|
280 |
leftTV.setInput(team); |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* The application entry point |
|
285 |
* |
|
286 |
* @param args |
|
287 |
* the command line arguments |
|
288 |
*/ |
|
289 |
public static void main(String[] args) { |
|
290 |
new PlayerTable().run(); |
|
291 |
} |
|
292 |
} |
|
0 | 293 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/PlayerTableModel.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
public class PlayerTableModel { |
|
4 |
public Team[] teams; |
|
5 |
|
|
6 |
/** |
|
7 |
* Constructs a PlayerTableModel Fills the model with data |
|
8 |
*/ |
|
9 |
public PlayerTableModel() { |
|
10 |
teams = new Team[3]; |
|
11 |
|
|
12 |
teams[0] = new Team("Celtics", "1985-86"); |
|
13 |
for (int i = 1 ; i <= 100 ; i++) { |
|
14 |
teams[0].add(new Player("N"+i, "M"+i, 25.8f, 9.8f, 6.8f)); |
|
15 |
} |
|
16 |
|
|
17 |
teams[1] = new Team("Bulls", "1995-96"); |
|
18 |
teams[1].add(new Player("Michael", "Jordan", 30.4f, 6.6f, 4.3f)); |
|
19 |
teams[1].add(new Player("Scottie", "Pippen", 19.4f, 6.4f, 5.9f)); |
|
20 |
teams[1].add(new Player("Toni", "Kukoc", 13.1f, 4.0f, 3.5f)); |
|
21 |
teams[1].add(new Player("Luc", "Longley", 9.1f, 5.1f, 1.9f)); |
|
22 |
teams[1].add(new Player("Steve", "Kerr", 8.4f, 1.3f, 2.3f)); |
|
23 |
teams[1].add(new Player("Ron", "Harper", 7.4f, 2.7f, 2.6f)); |
|
24 |
teams[1].add(new Player("Dennis", "Rodman", 5.5f, 14.9f, 2.5f)); |
|
25 |
teams[1].add(new Player("Bill", "Wennington", 5.3f, 2.5f, 0.6f)); |
|
26 |
teams[1].add(new Player("Jack", "Haley", 5.0f, 2.0f, 0.0f)); |
|
27 |
teams[1].add(new Player("John", "Salley", 4.4f, 3.3f, 1.3f)); |
|
28 |
teams[1].add(new Player("Jud", "Buechler", 3.8f, 1.5f, 0.8f)); |
|
29 |
teams[1].add(new Player("Dickey", "Simpkins", 3.6f, 2.6f, 0.6f)); |
|
30 |
teams[1].add(new Player("James", "Edwards", 3.5f, 1.4f, 0.4f)); |
|
31 |
teams[1].add(new Player("Jason", "Caffey", 3.2f, 1.9f, 0.4f)); |
|
32 |
teams[1].add(new Player("Randy", "Brown", 2.7f, 1.0f, 1.1f)); |
|
33 |
|
|
34 |
teams[2] = new Team("Lakers", "1987-1988"); |
|
35 |
teams[2].add(new Player("Magic", "Johnson", 23.9f, 6.3f, 12.2f)); |
|
36 |
teams[2].add(new Player("James", "Worthy", 19.4f, 5.7f, 2.8f)); |
|
37 |
teams[2].add(new Player("Kareem", "Abdul-Jabbar", 17.5f, 6.7f, 2.6f)); |
|
38 |
teams[2].add(new Player("Byron", "Scott", 17.0f, 3.5f, 3.4f)); |
|
39 |
teams[2].add(new Player("A.C.", "Green", 10.8f, 7.8f, 1.1f)); |
|
40 |
teams[2].add(new Player("Michael", "Cooper", 10.5f, 3.1f, 4.5f)); |
|
41 |
teams[2].add(new Player("Mychal", "Thompson", 10.1f, 4.1f, 0.8f)); |
|
42 |
teams[2].add(new Player("Kurt", "Rambis", 5.7f, 5.8f, 0.8f)); |
|
43 |
teams[2].add(new Player("Billy", "Thompson", 5.6f, 2.9f, 1.0f)); |
|
44 |
teams[2].add(new Player("Adrian", "Branch", 4.3f, 1.7f, 0.5f)); |
|
45 |
teams[2].add(new Player("Wes", "Matthews", 4.2f, 0.9f, 2.0f)); |
|
46 |
teams[2].add(new Player("Frank", "Brickowski", 4.0f, 2.6f, 0.3f)); |
|
47 |
teams[2].add(new Player("Mike", "Smrek", 2.2f, 1.1f, 0.1f)); |
|
48 |
} |
|
49 |
} |
|
0 | 50 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/Person.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
import org.eclipse.swt.graphics.RGB; |
|
4 |
|
|
5 |
public class Person { |
|
6 |
private String name; |
|
7 |
|
|
8 |
private boolean male; |
|
9 |
|
|
10 |
private Integer ageRange; |
|
11 |
|
|
12 |
private RGB shirtColor; |
|
13 |
|
|
14 |
/** |
|
15 |
* @return Returns the ageRange. |
|
16 |
*/ |
|
17 |
public Integer getAgeRange() { |
|
18 |
return ageRange; |
|
19 |
} |
|
20 |
|
|
21 |
/** |
|
22 |
* @param ageRange |
|
23 |
* The ageRange to set. |
|
24 |
*/ |
|
25 |
public void setAgeRange(Integer ageRange) { |
|
26 |
this.ageRange = ageRange; |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* @return Returns the male. |
|
31 |
*/ |
|
32 |
public boolean isMale() { |
|
33 |
return male; |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* @param male |
|
38 |
* The male to set. |
|
39 |
*/ |
|
40 |
public void setMale(boolean male) { |
|
41 |
this.male = male; |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* @return Returns the name. |
|
46 |
*/ |
|
47 |
public String getName() { |
|
48 |
return name; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* @param name |
|
53 |
* The name to set. |
|
54 |
*/ |
|
55 |
public void setName(String name) { |
|
56 |
this.name = name; |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* @return Returns the shirtColor. |
|
61 |
*/ |
|
62 |
public RGB getShirtColor() { |
|
63 |
return shirtColor; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* @param shirtColor |
|
68 |
* The shirtColor to set. |
|
69 |
*/ |
|
70 |
public void setShirtColor(RGB shirtColor) { |
|
71 |
this.shirtColor = shirtColor; |
|
72 |
} |
|
73 |
} |
|
0 | 74 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/Team.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
import java.util.Collections; |
|
4 |
import java.util.LinkedList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
public class Team { |
|
8 |
private String name; |
|
9 |
|
|
10 |
private String year; |
|
11 |
|
|
12 |
private List players; |
|
13 |
|
|
14 |
/** |
|
15 |
* Constructs a Team |
|
16 |
* |
|
17 |
* @param name |
|
18 |
* the name |
|
19 |
* @param year |
|
20 |
* the year |
|
21 |
*/ |
|
22 |
public Team(String name, String year) { |
|
23 |
this.name = name; |
|
24 |
this.year = year; |
|
25 |
players = new LinkedList(); |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Gets the name |
|
30 |
* |
|
31 |
* @return String |
|
32 |
*/ |
|
33 |
public String getName() { |
|
34 |
return name; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Gets the year |
|
39 |
* |
|
40 |
* @return String |
|
41 |
*/ |
|
42 |
public String getYear() { |
|
43 |
return year; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Adds a player |
|
48 |
* |
|
49 |
* @param player |
|
50 |
* the player to add |
|
51 |
* @return boolean |
|
52 |
*/ |
|
53 |
public boolean add(Player player) { |
|
54 |
boolean added = players.add(player); |
|
55 |
if (added) |
|
56 |
player.setTeam(this); |
|
57 |
return added; |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Gets the players |
|
62 |
* |
|
63 |
* @return List |
|
64 |
*/ |
|
65 |
public List getPlayers() { |
|
66 |
return Collections.unmodifiableList(players); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Returns whether the specified player led his team in the specified |
|
71 |
* category |
|
72 |
* |
|
73 |
* @param player |
|
74 |
* the player |
|
75 |
* @param column |
|
76 |
* the category |
|
77 |
* @return boolean |
|
78 |
*/ |
|
79 |
public boolean led(Player player, int column) { |
|
80 |
boolean led = true; |
|
81 |
|
|
82 |
// Go through all the players on the team, comparing the specified |
|
83 |
// player's |
|
84 |
// stats with each other player. |
|
85 |
for (int i = 0, n = players.size(); i < n && led; i++) { |
|
86 |
Player test = (Player) players.get(i); |
|
87 |
if (player == test) |
|
88 |
continue; |
|
89 |
switch (column) { |
|
90 |
case PlayerConst.COLUMN_POINTS: |
|
91 |
if (player.getPoints() < test.getPoints()) |
|
92 |
led = false; |
|
93 |
break; |
|
94 |
case PlayerConst.COLUMN_REBOUNDS: |
|
95 |
if (player.getRebounds() < test.getRebounds()) |
|
96 |
led = false; |
|
97 |
break; |
|
98 |
case PlayerConst.COLUMN_ASSISTS: |
|
99 |
if (player.getAssists() < test.getAssists()) |
|
100 |
led = false; |
|
101 |
break; |
|
102 |
} |
|
103 |
} |
|
104 |
return led; |
|
105 |
} |
|
106 |
} |
|
0 | 107 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/tableviewer/AgeRange.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.rcp.tableviewer; |
|
2 |
|
|
3 |
public class AgeRange { |
|
4 |
public static final String NONE = ""; |
|
5 |
|
|
6 |
public static final String BABY = "0 - 3"; |
|
7 |
|
|
8 |
public static final String TODDLER = "4 - 7"; |
|
9 |
|
|
10 |
public static final String CHILD = "8 - 12"; |
|
11 |
|
|
12 |
public static final String TEENAGER = "13 - 19"; |
|
13 |
|
|
14 |
public static final String ADULT = "20 - ?"; |
|
15 |
|
|
16 |
public static final String[] INSTANCES = { NONE, BABY, TODDLER, CHILD, |
|
17 |
TEENAGER, ADULT }; |
|
18 |
} |
|
0 | 19 |
tmp/org.txm.tmp.rcp/src/org/txm/tmp/rcp/views/SampleView.java (revision 512) | ||
---|---|---|
1 |
package org.txm.tmp.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.tmp.rcp.views.SampleView"; |
|
39 |
|
|
40 |
private TableViewer viewer; |
|
41 |
private Action action1; |
|
42 |
private Action action2; |
|
43 |
private Action doubleClickAction; |
|
44 |
|
|
45 |
/* |
|
46 |
* The content provider class is responsible for |
|
47 |
* providing objects to the view. It can wrap |
|
48 |
* existing objects in adapters or simply return |
|
49 |
* objects as-is. These objects may be sensitive |
|
50 |
* to the current input of the view, or ignore |
|
51 |
* it and always show the same content |
|
52 |
* (like Task List, for example). |
|
53 |
*/ |
|
54 |
|
|
55 |
class ViewContentProvider implements IStructuredContentProvider { |
|
56 |
public void inputChanged(Viewer v, Object oldInput, Object newInput) { |
|
57 |
} |
|
58 |
public void dispose() { |
|
59 |
} |
|
60 |
public Object[] getElements(Object parent) { |
|
61 |
return new String[] { "One", "Two", "Three" }; |
|
62 |
} |
|
63 |
} |
|
64 |
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { |
|
65 |
public String getColumnText(Object obj, int index) { |
|
66 |
return getText(obj); |
|
67 |
} |
|
68 |
public Image getColumnImage(Object obj, int index) { |
|
69 |
return getImage(obj); |
|
70 |
} |
|
71 |
public Image getImage(Object obj) { |
|
72 |
return PlatformUI.getWorkbench(). |
|
73 |
getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); |
|
74 |
} |
|
75 |
} |
|
76 |
class NameSorter extends ViewerSorter { |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* The constructor. |
|
81 |
*/ |
|
82 |
public SampleView() { |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* This is a callback that will allow us |
|
87 |
* to create the viewer and initialize it. |
|
88 |
*/ |
|
89 |
public void createPartControl(Composite parent) { |
|
90 |
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); |
|
91 |
viewer.setContentProvider(new ViewContentProvider()); |
|
92 |
viewer.setLabelProvider(new ViewLabelProvider()); |
|
93 |
viewer.setSorter(new NameSorter()); |
|
94 |
viewer.setInput(getViewSite()); |
|
95 |
|
|
96 |
// Create the help context id for the viewer's control |
|
97 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.txm.tmp.rcp.viewer"); |
|
98 |
makeActions(); |
|
99 |
hookContextMenu(); |
|
100 |
hookDoubleClickAction(); |
|
101 |
contributeToActionBars(); |
|
102 |
} |
|
103 |
|
|
104 |
private void hookContextMenu() { |
|
105 |
MenuManager menuMgr = new MenuManager("#PopupMenu"); |
|
106 |
menuMgr.setRemoveAllWhenShown(true); |
|
107 |
menuMgr.addMenuListener(new IMenuListener() { |
|
108 |
public void menuAboutToShow(IMenuManager manager) { |
|
109 |
SampleView.this.fillContextMenu(manager); |
|
110 |
} |
|
111 |
}); |
|
112 |
Menu menu = menuMgr.createContextMenu(viewer.getControl()); |
|
113 |
viewer.getControl().setMenu(menu); |
|
114 |
getSite().registerContextMenu(menuMgr, viewer); |
|
115 |
} |
|
116 |
|
|
117 |
private void contributeToActionBars() { |
|
118 |
IActionBars bars = getViewSite().getActionBars(); |
|
119 |
fillLocalPullDown(bars.getMenuManager()); |
|
120 |
fillLocalToolBar(bars.getToolBarManager()); |
|
121 |
} |
|
122 |
|
|
123 |
private void fillLocalPullDown(IMenuManager manager) { |
|
124 |
manager.add(action1); |
|
125 |
manager.add(new Separator()); |
|
126 |
manager.add(action2); |
|
127 |
} |
|
128 |
|
|
129 |
private void fillContextMenu(IMenuManager manager) { |
|
130 |
manager.add(action1); |
|
131 |
manager.add(action2); |
|
132 |
// Other plug-ins can contribute there actions here |
|
133 |
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
134 |
} |
|
135 |
|
|
136 |
private void fillLocalToolBar(IToolBarManager manager) { |
|
137 |
manager.add(action1); |
|
138 |
manager.add(action2); |
|
139 |
} |
|
140 |
|
|
141 |
private void makeActions() { |
|
142 |
action1 = new Action() { |
|
143 |
public void run() { |
|
144 |
showMessage("Action 1 executed"); |
|
145 |
} |
|
146 |
}; |
|
147 |
action1.setText("Action 1"); |
|
148 |
action1.setToolTipText("Action 1 tooltip"); |
|
149 |
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). |
|
150 |
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); |
|
151 |
|
|
152 |
action2 = new Action() { |
|
153 |
public void run() { |
|
154 |
showMessage("Action 2 executed"); |
|
155 |
} |
|
156 |
}; |
|
157 |
action2.setText("Action 2"); |
|
158 |
action2.setToolTipText("Action 2 tooltip"); |
|
159 |
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). |
|
160 |
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); |
|
161 |
doubleClickAction = new Action() { |
|
162 |
public void run() { |
|
163 |
ISelection selection = viewer.getSelection(); |
|
164 |
Object obj = ((IStructuredSelection)selection).getFirstElement(); |
|
165 |
showMessage("Double-click detected on "+obj.toString()); |
|
166 |
} |
|
167 |
}; |
|
168 |
} |
|
169 |
|
|
170 |
private void hookDoubleClickAction() { |
|
171 |
viewer.addDoubleClickListener(new IDoubleClickListener() { |
|
172 |
public void doubleClick(DoubleClickEvent event) { |
|
173 |
doubleClickAction.run(); |
|
174 |
} |
|
175 |
}); |
|
176 |
} |
|
177 |
private void showMessage(String message) { |
|
178 |
MessageDialog.openInformation( |
|
179 |
viewer.getControl().getShell(), |
|
180 |
"Sample View", |
|
181 |
message); |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Passing the focus request to the viewer's control. |
|
186 |
*/ |
|
187 |
public void setFocus() { |
|
188 |
viewer.getControl().setFocus(); |
|
189 |
} |
|
190 |
} |
|
0 | 191 |
tmp/org.txm.tmp.rcp/build.properties (revision 512) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = plugin.xml,\ |
|
4 |
META-INF/,\ |
|
5 |
.,\ |
|
6 |
icons/,\ |
|
7 |
contexts.xml |
|
0 | 8 |
Formats disponibles : Unified diff