Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 253105 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %bundleName
3
Bundle-Name: %bundleName
4
Bundle-SymbolicName: org.eclipse.pde.ui.templates;singleton:=true
4
Bundle-SymbolicName: org.eclipse.pde.ui.templates;singleton:=true
5
Bundle-Version: 3.4.100.qualifier
5
Bundle-Version: 3.6.0.qualifier
6
Bundle-Vendor: %bundleVendor
6
Bundle-Vendor: %bundleVendor
7
Bundle-RequiredExecutionEnvironment: J2SE-1.4
7
Bundle-RequiredExecutionEnvironment: J2SE-1.4
8
Export-Package: org.eclipse.pde.internal.ui.templates;x-internal:=true,
8
Export-Package: org.eclipse.pde.internal.ui.templates;x-internal:=true,
(-)plugin.properties (-2 / +3 lines)
Lines 103-110 Link Here
103
pluginContent.mail.name = RCP Mail Template
103
pluginContent.mail.name = RCP Mail Template
104
pluginContent.mail.description=\
104
pluginContent.mail.description=\
105
<p>This wizard creates a standalone RCP application that shows how to:</p>\
105
<p>This wizard creates a standalone RCP application that shows how to:</p>\
106
<li>add top-level menu and toolbar with actions</li>\
106
<li>add top-level menu and toolbar with actions (since 3.4 with commands)</li>\
107
<li>add keybindings to actions</li>\
107
<li>add keybindings to actions (since 3.4 to commands)</li>\
108
<li>create views that can't be closed and multiple instances of the same view</li>\
108
<li>create views that can't be closed and multiple instances of the same view</li>\
109
<li>create perspectives with placeholders for new views</li>\
109
<li>create perspectives with placeholders for new views</li>\
110
<li>use the default About dialog</li>\
110
<li>use the default About dialog</li>\
Lines 113-118 Link Here
113
<li>org.eclipse.core.runtime.applications</li>\
113
<li>org.eclipse.core.runtime.applications</li>\
114
<li>org.eclipse.core.runtime.products</li>\
114
<li>org.eclipse.core.runtime.products</li>\
115
<li>org.eclipse.ui.commands</li>\
115
<li>org.eclipse.ui.commands</li>\
116
<li>org.eclipse.ui.menus (since 3.4)</li>\
116
<li>org.eclipse.ui.perspectives</li>\
117
<li>org.eclipse.ui.perspectives</li>\
117
<li>org.eclipse.ui.views</li>
118
<li>org.eclipse.ui.views</li>
118
119
(-)src/org/eclipse/pde/internal/ui/templates/rcp/MailTemplate.java (-19 / +96 lines)
Lines 14-29 Link Here
14
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.jface.wizard.Wizard;
16
import org.eclipse.jface.wizard.WizardPage;
16
import org.eclipse.jface.wizard.WizardPage;
17
import org.eclipse.pde.core.plugin.IPluginBase;
17
import org.eclipse.pde.core.plugin.*;
18
import org.eclipse.pde.core.plugin.IPluginElement;
18
import org.eclipse.pde.internal.ui.templates.*;
19
import org.eclipse.pde.core.plugin.IPluginExtension;
20
import org.eclipse.pde.core.plugin.IPluginModelBase;
21
import org.eclipse.pde.core.plugin.IPluginReference;
22
import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
23
import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
24
import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
25
import org.eclipse.pde.ui.IFieldData;
19
import org.eclipse.pde.ui.IFieldData;
26
import org.eclipse.pde.ui.templates.PluginReference;
20
import org.eclipse.pde.ui.templates.PluginReference;
21
import org.eclipse.ui.IWorkbenchActionConstants;
22
import org.eclipse.ui.menus.MenuUtil;
27
23
28
public class MailTemplate extends PDETemplateSection {
24
public class MailTemplate extends PDETemplateSection {
29
25
Lines 79-89 Link Here
79
		createApplicationExtension();
75
		createApplicationExtension();
80
		createPerspectiveExtension();
76
		createPerspectiveExtension();
81
		createViewExtension();
77
		createViewExtension();
82
		if (getTargetVersion() >= 3.1) {
78
83
			createCommandExtension(false);
79
		boolean useKeyBindings = (getTargetVersion() >= 3.1);
80
		boolean useCommandsOnly = (getTargetVersion() >= 3.4);
81
82
		createCommandExtension(!useKeyBindings, useCommandsOnly);
83
		if (useKeyBindings) {
84
			createBindingsExtension();
84
			createBindingsExtension();
85
		} else {
85
		}
86
			createCommandExtension(true);
86
		if (useCommandsOnly) {
87
			createUiMenuExtension();
87
		}
88
		}
88
		createProductExtension();
89
		createProductExtension();
89
	}
90
	}
Lines 149-155 Link Here
149
			plugin.add(extension);
150
			plugin.add(extension);
150
	}
151
	}
151
152
152
	private void createCommandExtension(boolean generateKeyBindings) throws CoreException {
153
	private void createCommandExtension(boolean generateOldKeyBindings, boolean useCommandsOnly) throws CoreException {
153
		IPluginBase plugin = model.getPluginBase();
154
		IPluginBase plugin = model.getPluginBase();
154
		String id = plugin.getId();
155
		String id = plugin.getId();
155
		IPluginExtension extension = createExtension("org.eclipse.ui.commands", true); //$NON-NLS-1$
156
		IPluginExtension extension = createExtension("org.eclipse.ui.commands", true); //$NON-NLS-1$
Lines 162-169 Link Here
162
163
163
		element = model.getPluginFactory().createElement(extension);
164
		element = model.getPluginFactory().createElement(extension);
164
		element.setName("command"); //$NON-NLS-1$
165
		element.setName("command"); //$NON-NLS-1$
165
		element.setAttribute("description", "Opens a mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
166
		if (useCommandsOnly) {
166
		element.setAttribute("name", "Open Mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
167
			element.setAttribute("description", "Opens Another Message View"); //$NON-NLS-1$ //$NON-NLS-2$
168
			element.setAttribute("name", "Open Another Message View"); //$NON-NLS-1$ //$NON-NLS-2$
169
			element.setAttribute("defaultHandler", getStringOption(KEY_PACKAGE_NAME) + ".OpenViewHandler"); //$NON-NLS-1$ //$NON-NLS-2$
170
		} else {
171
			element.setAttribute("description", "Opens a mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
172
			element.setAttribute("name", "Open Mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
173
		}
167
		element.setAttribute("id", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
174
		element.setAttribute("id", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
168
		element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
175
		element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
169
		extension.add(element);
176
		extension.add(element);
Lines 174-182 Link Here
174
		element.setAttribute("name", "Open Message Dialog"); //$NON-NLS-1$ //$NON-NLS-2$
181
		element.setAttribute("name", "Open Message Dialog"); //$NON-NLS-1$ //$NON-NLS-2$
175
		element.setAttribute("id", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
182
		element.setAttribute("id", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
176
		element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
183
		element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
184
		if (useCommandsOnly) {
185
			element.setAttribute("defaultHandler", getStringOption(KEY_PACKAGE_NAME) + ".OpenMessageHandler"); //$NON-NLS-1$ //$NON-NLS-2$
186
		}
177
		extension.add(element);
187
		extension.add(element);
178
188
179
		if (generateKeyBindings) {
189
		if (generateOldKeyBindings) {
180
			element = model.getPluginFactory().createElement(extension);
190
			element = model.getPluginFactory().createElement(extension);
181
			element.setName("keyConfiguration"); //$NON-NLS-1$
191
			element.setName("keyConfiguration"); //$NON-NLS-1$
182
			element.setAttribute("description", "The key configuration for this sample"); //$NON-NLS-1$ //$NON-NLS-2$
192
			element.setAttribute("description", "The key configuration for this sample"); //$NON-NLS-1$ //$NON-NLS-2$
Lines 218-238 Link Here
218
		IPluginElement element = model.getPluginFactory().createElement(extension);
228
		IPluginElement element = model.getPluginFactory().createElement(extension);
219
		element.setName("key"); //$NON-NLS-1$
229
		element.setName("key"); //$NON-NLS-1$
220
		element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
230
		element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
221
		element.setAttribute("sequence", "CTRL+2"); //$NON-NLS-1$ //$NON-NLS-2$
231
		element.setAttribute("sequence", "M1+2"); //$NON-NLS-1$ //$NON-NLS-2$
222
		element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
232
		element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
223
		extension.add(element);
233
		extension.add(element);
224
234
225
		element = model.getPluginFactory().createElement(extension);
235
		element = model.getPluginFactory().createElement(extension);
226
		element.setName("key"); //$NON-NLS-1$
236
		element.setName("key"); //$NON-NLS-1$
227
		element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
237
		element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
228
		element.setAttribute("sequence", "CTRL+3"); //$NON-NLS-1$ //$NON-NLS-2$
238
		element.setAttribute("sequence", "M1+3"); //$NON-NLS-1$ //$NON-NLS-2$
229
		element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
239
		element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
230
		extension.add(element);
240
		extension.add(element);
231
241
232
		element = model.getPluginFactory().createElement(extension);
242
		element = model.getPluginFactory().createElement(extension);
233
		element.setName("key"); //$NON-NLS-1$
243
		element.setName("key"); //$NON-NLS-1$
234
		element.setAttribute("commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
244
		element.setAttribute("commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
235
		element.setAttribute("sequence", "CTRL+X"); //$NON-NLS-1$ //$NON-NLS-2$
245
		element.setAttribute("sequence", "M1+X"); //$NON-NLS-1$ //$NON-NLS-2$
236
		element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
246
		element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
237
		extension.add(element);
247
		extension.add(element);
238
248
Lines 240-245 Link Here
240
			plugin.add(extension);
250
			plugin.add(extension);
241
	}
251
	}
242
252
253
	private void createUiMenuExtension() throws CoreException {
254
		IPluginBase plugin = model.getPluginBase();
255
		String id = plugin.getId();
256
		IPluginExtension extension = createExtension("org.eclipse.ui.menus", true); //$NON-NLS-1$
257
258
		IPluginElement menuContribution = model.getPluginFactory().createElement(extension);
259
		menuContribution.setName("menuContribution"); //$NON-NLS-1$
260
		menuContribution.setAttribute("locationURI", MenuUtil.MAIN_MENU); //$NON-NLS-1$
261
		extension.add(menuContribution);
262
263
		IPluginElement fileMenu = model.getPluginFactory().createElement(extension);
264
		fileMenu.setName("menu"); //$NON-NLS-1$
265
		fileMenu.setAttribute("id", IWorkbenchActionConstants.M_FILE); //$NON-NLS-1$
266
		fileMenu.setAttribute("label", "&File"); //$NON-NLS-1$ //$NON-NLS-2$
267
		menuContribution.add(fileMenu);
268
269
		addMenuCommandElement(model, fileMenu, "org.eclipse.ui.window.newWindow", null); //$NON-NLS-1$
270
		addMenuSeparatorElement(model, fileMenu, IWorkbenchActionConstants.M_FILE + ".separator1"); //$NON-NLS-1$
271
		addMenuCommandElement(model, fileMenu, id + ".openMessage", "icons/sample3.gif"); //$NON-NLS-1$ //$NON-NLS-2$
272
		addMenuCommandElement(model, fileMenu, id + ".open", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
273
		addMenuSeparatorElement(model, fileMenu, IWorkbenchActionConstants.M_FILE + ".separator2"); //$NON-NLS-1$
274
		addMenuCommandElement(model, fileMenu, "org.eclipse.ui.file.exit", null); //$NON-NLS-1$
275
276
		IPluginElement helpMenu = model.getPluginFactory().createElement(extension);
277
		helpMenu.setName("menu"); //$NON-NLS-1$
278
		helpMenu.setAttribute("id", IWorkbenchActionConstants.M_HELP); //$NON-NLS-1$
279
		helpMenu.setAttribute("label", "&Help"); //$NON-NLS-1$ //$NON-NLS-2$
280
		menuContribution.add(helpMenu);
281
282
		addMenuCommandElement(model, helpMenu, "org.eclipse.ui.help.aboutAction", null); //$NON-NLS-1$
283
284
		IPluginElement toolbarContribution = model.getPluginFactory().createElement(extension);
285
		toolbarContribution.setName("menuContribution"); //$NON-NLS-1$
286
		toolbarContribution.setAttribute("locationURI", MenuUtil.MAIN_TOOLBAR); //$NON-NLS-1$
287
		extension.add(toolbarContribution);
288
289
		IPluginElement mainToolbar = model.getPluginFactory().createElement(extension);
290
		mainToolbar.setName("toolbar"); //$NON-NLS-1$
291
		mainToolbar.setAttribute("id", "main"); //$NON-NLS-1$ //$NON-NLS-2$
292
		toolbarContribution.add(mainToolbar);
293
294
		addMenuCommandElement(model, mainToolbar, id + ".openMessage", "icons/sample3.gif"); //$NON-NLS-1$ //$NON-NLS-2$
295
		addMenuCommandElement(model, mainToolbar, id + ".open", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
296
297
		if (!extension.isInTheModel())
298
			plugin.add(extension);
299
	}
300
301
	private void addMenuCommandElement(IPluginModelBase model, IPluginElement menuElement, String commandId, String icon) throws CoreException {
302
		IPluginElement commandElement = model.getPluginFactory().createElement(menuElement);
303
		commandElement.setName("command"); //$NON-NLS-1$
304
		commandElement.setAttribute("commandId", commandId); //$NON-NLS-1$
305
		commandElement.setAttribute("style", "push"); //$NON-NLS-1$ //$NON-NLS-2$
306
		if (icon != null) {
307
			commandElement.setAttribute("icon", icon); //$NON-NLS-1$
308
		}
309
		menuElement.add(commandElement);
310
	}
311
312
	private void addMenuSeparatorElement(IPluginModelBase model, IPluginElement menuElement, String name) throws CoreException {
313
		IPluginElement commandElement = model.getPluginFactory().createElement(menuElement);
314
		commandElement.setName("separator"); //$NON-NLS-1$
315
		commandElement.setAttribute("name", name); //$NON-NLS-1$
316
		commandElement.setAttribute("visible", "true"); //$NON-NLS-1$ //$NON-NLS-2$
317
		menuElement.add(commandElement);
318
	}
319
243
	private void createProductExtension() throws CoreException {
320
	private void createProductExtension() throws CoreException {
244
		IPluginBase plugin = model.getPluginBase();
321
		IPluginBase plugin = model.getPluginBase();
245
		IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); //$NON-NLS-1$
322
		IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); //$NON-NLS-1$
(-)templates_3.4/mail/java/$applicationClass$.java (+45 lines)
Added Link Here
1
package $packageName$;
2
3
import org.eclipse.equinox.app.IApplication;
4
import org.eclipse.equinox.app.IApplicationContext;
5
import org.eclipse.swt.widgets.Display;
6
import org.eclipse.ui.IWorkbench;
7
import org.eclipse.ui.PlatformUI;
8
9
/**
10
 * This class controls all aspects of the application's execution
11
 */
12
public class $applicationClass$ implements IApplication {
13
14
	/* (non-Javadoc)
15
	 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
16
	 */
17
	public Object start(IApplicationContext context) {
18
		Display display = PlatformUI.createDisplay();
19
		try {
20
			int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
21
			if (returnCode == PlatformUI.RETURN_RESTART) {
22
				return IApplication.EXIT_RESTART;
23
			}
24
			return IApplication.EXIT_OK;
25
		} finally {
26
			display.dispose();
27
		}
28
	}
29
30
	/* (non-Javadoc)
31
	 * @see org.eclipse.equinox.app.IApplication#stop()
32
	 */
33
	public void stop() {
34
		if (!PlatformUI.isWorkbenchRunning())
35
			return;
36
		final IWorkbench workbench = PlatformUI.getWorkbench();
37
		final Display display = workbench.getDisplay();
38
		display.syncExec(new Runnable() {
39
			public void run() {
40
				if (!display.isDisposed())
41
					workbench.close();
42
			}
43
		});
44
	}
45
}
(-)templates_3.4/mail/java/ApplicationWorkbenchAdvisor.java (+21 lines)
Added Link Here
1
package $packageName$;
2
3
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
4
import org.eclipse.ui.application.WorkbenchAdvisor;
5
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
6
7
/**
8
 * This workbench advisor creates the window advisor, and specifies
9
 * the perspective id for the initial window.
10
 */
11
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
12
	
13
    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
14
        return new ApplicationWorkbenchWindowAdvisor(configurer);
15
    }
16
17
	public String getInitialWindowPerspectiveId() {
18
		return Perspective.ID;
19
	} 
20
	
21
}
(-)templates_3.4/mail/java/ApplicationWorkbenchWindowAdvisor.java (+20 lines)
Added Link Here
1
package $packageName$;
2
3
import org.eclipse.swt.graphics.Point;
4
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
5
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
6
7
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
8
9
    public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
10
        super(configurer);
11
    }
12
13
    public void preWindowOpen() {
14
        IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
15
        configurer.setInitialSize(new Point(600, 400));
16
        configurer.setShowCoolBar(true);
17
        configurer.setShowStatusLine(false);
18
    }
19
    
20
}
(-)templates_3.4/mail/java/ICommandIds.java (+15 lines)
Added Link Here
1
package $packageName$;
2
3
/**
4
 * Interface defining the application's command IDs.
5
 * Key bindings can be defined for specific commands.
6
 * To associate an action with a command, use IAction.setActionDefinitionId(commandId).
7
 *
8
 * @see org.eclipse.jface.action.IAction#setActionDefinitionId(String)
9
 */
10
public interface ICommandIds {
11
12
    public static final String CMD_OPEN = "$pluginId$.open";
13
    public static final String CMD_OPEN_MESSAGE = "$pluginId$.openMessage";
14
    
15
}
(-)templates_3.4/mail/java/NavigationView.java (+151 lines)
Added Link Here
1
package $packageName$;
2
3
import java.util.ArrayList;
4
5
import org.eclipse.jface.viewers.IStructuredContentProvider;
6
import org.eclipse.jface.viewers.ITreeContentProvider;
7
import org.eclipse.jface.viewers.LabelProvider;
8
import org.eclipse.jface.viewers.TreeViewer;
9
import org.eclipse.jface.viewers.Viewer;
10
import org.eclipse.swt.SWT;
11
import org.eclipse.swt.graphics.Image;
12
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.ui.ISharedImages;
14
import org.eclipse.ui.PlatformUI;
15
import org.eclipse.ui.part.ViewPart;
16
17
public class NavigationView extends ViewPart {
18
	public static final String ID = "$pluginId$.navigationView";
19
	private TreeViewer viewer;
20
	 
21
	class TreeObject {
22
		private String name;
23
		private TreeParent parent;
24
		
25
		public TreeObject(String name) {
26
			this.name = name;
27
		}
28
		public String getName() {
29
			return name;
30
		}
31
		public void setParent(TreeParent parent) {
32
			this.parent = parent;
33
		}
34
		public TreeParent getParent() {
35
			return parent;
36
		}
37
		public String toString() {
38
			return getName();
39
		}
40
	}
41
	
42
	class TreeParent extends TreeObject {
43
		private ArrayList children;
44
		public TreeParent(String name) {
45
			super(name);
46
			children = new ArrayList();
47
		}
48
		public void addChild(TreeObject child) {
49
			children.add(child);
50
			child.setParent(this);
51
		}
52
		public void removeChild(TreeObject child) {
53
			children.remove(child);
54
			child.setParent(null);
55
		}
56
		public TreeObject[] getChildren() {
57
			return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
58
		}
59
		public boolean hasChildren() {
60
			return children.size()>0;
61
		}
62
	}
63
64
	class ViewContentProvider implements IStructuredContentProvider, 
65
										   ITreeContentProvider {
66
67
        public void inputChanged(Viewer v, Object oldInput, Object newInput) {
68
		}
69
        
70
		public void dispose() {
71
		}
72
        
73
		public Object[] getElements(Object parent) {
74
			return getChildren(parent);
75
		}
76
        
77
		public Object getParent(Object child) {
78
			if (child instanceof TreeObject) {
79
				return ((TreeObject)child).getParent();
80
			}
81
			return null;
82
		}
83
        
84
		public Object[] getChildren(Object parent) {
85
			if (parent instanceof TreeParent) {
86
				return ((TreeParent)parent).getChildren();
87
			}
88
			return new Object[0];
89
		}
90
91
        public boolean hasChildren(Object parent) {
92
			if (parent instanceof TreeParent)
93
				return ((TreeParent)parent).hasChildren();
94
			return false;
95
		}
96
	}
97
	
98
	class ViewLabelProvider extends LabelProvider {
99
100
		public String getText(Object obj) {
101
			return obj.toString();
102
		}
103
		public Image getImage(Object obj) {
104
			String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
105
			if (obj instanceof TreeParent)
106
			   imageKey = ISharedImages.IMG_OBJ_FOLDER;
107
			return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
108
		}
109
	}
110
111
    /**
112
     * We will set up a dummy model to initialize tree heararchy. In real
113
     * code, you will connect to a real model and expose its hierarchy.
114
     */
115
    private TreeObject createDummyModel() {
116
        TreeObject to1 = new TreeObject("Inbox");
117
        TreeObject to2 = new TreeObject("Drafts");
118
        TreeObject to3 = new TreeObject("Sent");
119
        TreeParent p1 = new TreeParent("me@this.com");
120
        p1.addChild(to1);
121
        p1.addChild(to2);
122
        p1.addChild(to3);
123
124
        TreeObject to4 = new TreeObject("Inbox");
125
        TreeParent p2 = new TreeParent("other@aol.com");
126
        p2.addChild(to4);
127
128
        TreeParent root = new TreeParent("");
129
        root.addChild(p1);
130
        root.addChild(p2);
131
        return root;
132
    }
133
134
	/**
135
     * This is a callback that will allow us to create the viewer and initialize
136
     * it.
137
     */
138
	public void createPartControl(Composite parent) {
139
		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
140
		viewer.setContentProvider(new ViewContentProvider());
141
		viewer.setLabelProvider(new ViewLabelProvider());
142
		viewer.setInput(createDummyModel());
143
	}
144
145
	/**
146
	 * Passing the focus request to the viewer's control.
147
	 */
148
	public void setFocus() {
149
		viewer.getControl().setFocus();
150
	}
151
}
(-)templates_3.4/mail/java/OpenMessageHandler.java (+15 lines)
Added Link Here
1
package $packageName$;
2
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.jface.dialogs.MessageDialog;
7
import org.eclipse.ui.handlers.HandlerUtil;
8
9
public class OpenMessageHandler extends AbstractHandler {
10
11
	public Object execute(ExecutionEvent event) throws ExecutionException {
12
        MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Open", "Open Message Dialog!");
13
        return null;
14
	}
15
}
(-)templates_3.4/mail/java/OpenViewHandler.java (+28 lines)
Added Link Here
1
package $packageName$;
2
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.jface.dialogs.MessageDialog;
7
import org.eclipse.ui.IWorkbenchPage;
8
import org.eclipse.ui.IWorkbenchWindow;
9
import org.eclipse.ui.PartInitException;
10
import org.eclipse.ui.handlers.HandlerUtil;
11
12
public class OpenViewHandler extends AbstractHandler {
13
14
	private int instanceNum = 0;
15
16
	public Object execute(ExecutionEvent event) throws ExecutionException {
17
18
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
19
20
		try {
21
			window.getActivePage().showView(View.ID, Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE);
22
		} catch (PartInitException e) {
23
			MessageDialog.openError(window.getShell(), "Error", "Error opening view:" + e.getMessage());
24
		}
25
26
		return null;
27
	}
28
}
(-)templates_3.4/mail/java/Perspective.java (+25 lines)
Added Link Here
1
package $packageName$;
2
3
import org.eclipse.ui.IFolderLayout;
4
import org.eclipse.ui.IPageLayout;
5
import org.eclipse.ui.IPerspectiveFactory;
6
7
public class Perspective implements IPerspectiveFactory {
8
9
	/**
10
	 * The ID of the perspective as specified in the extension.
11
	 */
12
	public static final String ID = "$pluginId$.perspective";
13
14
	public void createInitialLayout(IPageLayout layout) {
15
		String editorArea = layout.getEditorArea();
16
		layout.setEditorAreaVisible(false);
17
		
18
		layout.addStandaloneView(NavigationView.ID,  false, IPageLayout.LEFT, 0.25f, editorArea);
19
		IFolderLayout folder = layout.createFolder("messages", IPageLayout.TOP, 0.5f, editorArea);
20
		folder.addPlaceholder(View.ID + ":*");
21
		folder.addView(View.ID);
22
		
23
		layout.getViewLayout(NavigationView.ID).setCloseable(false);
24
	}
25
}
(-)templates_3.4/mail/java/View.java (+77 lines)
Added Link Here
1
package $packageName$;
2
3
import org.eclipse.jface.dialogs.MessageDialog;
4
import org.eclipse.jface.resource.JFaceResources;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.events.SelectionAdapter;
7
import org.eclipse.swt.events.SelectionEvent;
8
import org.eclipse.swt.graphics.Font;
9
import org.eclipse.swt.layout.GridData;
10
import org.eclipse.swt.layout.GridLayout;
11
import org.eclipse.swt.widgets.Composite;
12
import org.eclipse.swt.widgets.Label;
13
import org.eclipse.swt.widgets.Link;
14
import org.eclipse.swt.widgets.Text;
15
import org.eclipse.ui.part.ViewPart;
16
17
public class View extends ViewPart {
18
19
	public static final String ID = "$pluginId$.view";
20
	
21
	public void createPartControl(Composite parent) {
22
		Composite top = new Composite(parent, SWT.NONE);
23
		GridLayout layout = new GridLayout();
24
		layout.marginHeight = 0;
25
		layout.marginWidth = 0;
26
		top.setLayout(layout);
27
		// top banner
28
		Composite banner = new Composite(top, SWT.NONE);
29
		banner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_BEGINNING, true, false));
30
		layout = new GridLayout();
31
		layout.marginHeight = 5;
32
		layout.marginWidth = 10;
33
		layout.numColumns = 2;
34
		banner.setLayout(layout);
35
		
36
		// setup bold font
37
		Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);    
38
		
39
		Label l = new Label(banner, SWT.WRAP);
40
		l.setText("Subject:");
41
		l.setFont(boldFont);
42
		l = new Label(banner, SWT.WRAP);
43
		l.setText("This is a message about the cool Eclipse RCP!");
44
		
45
		l = new Label(banner, SWT.WRAP);
46
		l.setText("From:");
47
		l.setFont(boldFont);
48
    
49
		final Link link = new Link(banner, SWT.NONE);
50
		link.setText("<a>nicole@mail.org</a>");
51
		link.addSelectionListener(new SelectionAdapter() {    
52
			public void widgetSelected(SelectionEvent e) {
53
				MessageDialog.openInformation(getSite().getShell(), "Not Implemented", "Imagine the address book or a new message being created now.");
54
			}    
55
		});
56
    
57
		l = new Label(banner, SWT.WRAP);
58
		l.setText("Date:");
59
		l.setFont(boldFont);
60
		l = new Label(banner, SWT.WRAP);
61
		l.setText("10:34 am");
62
		// message contents
63
		Text text = new Text(top, SWT.MULTI | SWT.WRAP);
64
		text.setText("This RCP Application was generated from the PDE Plug-in Project wizard. This sample shows how to:\n"+
65
						"- add a top-level menu and toolbar with commands\n"+
66
						"- add keybindings to commands\n" +
67
						"- create views that can't be closed and\n"+
68
						"  multiple instances of the same view\n"+
69
						"- perspectives with placeholders for new views\n"+
70
						"- use the default about dialog\n"+
71
						"- create a product definition\n");
72
		text.setLayoutData(new GridData(GridData.FILL_BOTH));
73
	}
74
75
	public void setFocus() {
76
	}
77
}

Return to bug 253105