Debian Codegraph @

plugins/org.eclipse.emf.codegen.ecore/templates/editor/Advisor.javajet

raw
1 <%@ jet package="org.eclipse.emf.codegen.ecore.templates.editor" imports="org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.emf.codegen.ecore.genmodel.util.GenModelUtil" class="Advisor"%>
2 <%
3 /**
4 * Copyright (c) 2004-2010 IBM Corporation and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v2.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v20.html
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 */
13 %>
14 <%GenModel genModel = (GenModel)argument;%>
15 <%final boolean isJDK50 = genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50;%>
16 <%String _ListOfString = "List" + (genModel.useGenerics() ? "<String>" : "");%>
17 <%String _UniqueEListOfString = "UniqueEList" + (genModel.useGenerics() ? "<String>" : "");%>
18 <%String _StringBuilder = genModel.getImportedName(genModel.useGenerics() ? "java.lang.StringBuilder" : "java.lang.StringBuffer");%>
19 <%@ include file="../Header.javajetinc"%>
20 package <%=genModel.getEditorPluginPackageName()%>;
21
22 <%if (!genModel.isRichAjaxPlatform()) {%>
23 import java.io.File;
24 import java.util.Arrays;
25 <%}%>
26 <%if (!genModel.useGenerics()) {%>
27 import java.util.Iterator;
28 <%}%>
29 <%if (genModel.getAllGenPackagesWithConcreteClasses().size() > 1) {%>
30 import java.util.List;
31 <%}%>
32
33 import org.eclipse.equinox.app.IApplication;
34 import org.eclipse.equinox.app.IApplicationContext;
35
36 import org.eclipse.jface.action.GroupMarker;
37 import org.eclipse.jface.action.IAction;
38 import org.eclipse.jface.action.IMenuManager;
39 import org.eclipse.jface.action.MenuManager;
40 import org.eclipse.jface.action.Separator;
41 import org.eclipse.jface.dialogs.MessageDialog;
42 import org.eclipse.jface.window.Window;
43 <%if (!genModel.isRichAjaxPlatform()) {%>
44 import org.eclipse.swt.SWT;
45 <%}%>
46 import org.eclipse.swt.graphics.Point;
47 import org.eclipse.swt.widgets.Display;
48 <%if (!genModel.isRichAjaxPlatform()) {%>
49 import org.eclipse.swt.widgets.FileDialog;
50 import org.eclipse.swt.widgets.Shell;
51 <%}%>
52 import org.eclipse.ui.IEditorDescriptor;
53 import org.eclipse.ui.IFolderLayout;
54 import org.eclipse.ui.IPageLayout;
55 import org.eclipse.ui.IPerspectiveFactory;
56 import org.eclipse.ui.IWorkbench;
57 import org.eclipse.ui.IWorkbenchActionConstants;
58 import org.eclipse.ui.IWorkbenchPage;
59 import org.eclipse.ui.IWorkbenchWindow;
60 import org.eclipse.ui.PartInitException;
61 import org.eclipse.ui.PlatformUI;
62 import org.eclipse.ui.actions.ActionFactory;
63 <%if (!genModel.isRichAjaxPlatform()) {%>
64 import org.eclipse.ui.actions.ContributionItemFactory;
65 <%}%>
66 import org.eclipse.ui.application.ActionBarAdvisor;
67 import org.eclipse.ui.application.IActionBarConfigurer;
68 import org.eclipse.ui.application.IWorkbenchConfigurer;
69 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
70 import org.eclipse.ui.application.WorkbenchAdvisor;
71 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
72
73 import org.eclipse.emf.common.ui.URIEditorInput;
74 import org.eclipse.emf.common.ui.action.WorkbenchWindowActionDelegate;
75 import org.eclipse.emf.common.util.URI;
76 <%if (genModel.getAllGenPackagesWithConcreteClasses().size() > 1) {%>
77 import org.eclipse.emf.common.util.UniqueEList;
78 <%}%>
79 import org.eclipse.emf.edit.ui.action.LoadResourceAction;
80 import org.eclipse.emf.edit.ui.util.EditUIUtil;
81
82 import <%=genModel.getQualifiedEditorPluginClassName()%>;
83 <%genModel.markImportLocation(stringBuffer);%>
84
85
86 /**
87 * Customized {@link WorkbenchAdvisor} for the RCP application.
88 * <!-- begin-user-doc -->
89 * <!-- end-user-doc -->
90 <%if (genModel.hasAPITags()) {%>
91 * <%=genModel.getAPITags(genModel.getIndentation(stringBuffer))%>
92 <%}%>
93 * @generated
94 */
95 <%if (isJDK50 && genModel.hasAPIDeprecatedTag()) {%>
96 @Deprecated
97 <%} else if (isJDK50 && GenModelUtil.hasAPIDeprecatedTag(genModel.getAllGenPackagesWithConcreteClasses())) {%>
98 @SuppressWarnings("deprecation")
99 <%}%>
100 public final class <%=genModel.getEditorAdvisorClassName()%> extends WorkbenchAdvisor
101 {
102 <%if (genModel.hasCopyrightField()) {%>
103 /**
104 * <!-- begin-user-doc -->
105 * <!-- end-user-doc -->
106 * @generated
107 */
108 public static final String copyright = <%=genModel.getCopyrightFieldLiteral()%>;<%=genModel.getNonNLS()%>
109
110 <%}%>
111 <%if (!genModel.isRichAjaxPlatform()) {%>
112 /**
113 * The default file extension filters for use in dialogs.
114 * <!-- begin-user-doc -->
115 * <!-- end-user-doc -->
116 * @generated
117 */
118 <%if (genModel.getAllGenPackagesWithConcreteClasses().size() == 1) {%>
119 private static final String[] FILE_EXTENSION_FILTERS = <%if (!genModel.useGenerics()) {%>(String[])<%}%><%=genModel.getAllGenPackagesWithConcreteClasses().get(0).getImportedEditorClassName()%>.FILE_EXTENSION_FILTERS.toArray(new String[0]);
120 <%} else {%>
121 private static final String[] FILE_EXTENSION_FILTERS = getFileExtensionFilters();
122
123 /**
124 * Returns the default file extension filters. This method should only be used to initialize {@link #FILE_EXTENSION_FILTERS}.
125 * <!-- begin-user-doc -->
126 * <!-- end-user-doc -->
127 * @generated
128 */
129 private static String[] getFileExtensionFilters()
130 {
131 <%=_ListOfString%> result = new <%=_UniqueEListOfString%>();
132 <%for (GenPackage genPackage : genModel.getAllGenPackagesWithConcreteClasses()) {%>
133 result.addAll(<%=genPackage.getImportedEditorClassName()%>.FILE_EXTENSION_FILTERS);
134 <%}%>
135 return <%if (!genModel.useGenerics()) {%>(String[])<%}%>result.toArray(new String[0]);
136 }
137 <%}%>
138 <%}%>
139
140 /**
141 * This looks up a string in the plugin's plugin.properties file.
142 * <!-- begin-user-doc -->
143 * <!-- end-user-doc -->
144 * @generated
145 */
146 private static String getString(String key)
147 {
148 return <%=genModel.getEditorPluginClassName()%>.INSTANCE.getString(key);
149 }
150
151 /**
152 * This looks up a string in plugin.properties, making a substitution.
153 * <!-- begin-user-doc -->
154 * <!-- end-user-doc -->
155 * @generated
156 */
157 private static String getString(String key, Object s1)
158 {
159 return <%=genModel.getQualifiedEditorPluginClassName()%>.INSTANCE.getString(key, new Object [] { s1 });
160 }
161
162 /**
163 * RCP's application
164 * <!-- begin-user-doc -->
165 * <!-- end-user-doc -->
166 * @generated
167 */
168 public static class Application implements IApplication
169 {
170 /**
171 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
172 * <!-- begin-user-doc -->
173 * <!-- end-user-doc -->
174 * @generated
175 */
176 <%if (genModel.useInterfaceOverrideAnnotation()){%>
177 @Override
178 <%}%>
179 public Object start(IApplicationContext context) throws Exception
180 {
181 WorkbenchAdvisor workbenchAdvisor = new <%=genModel.getEditorAdvisorClassName()%>();
182 Display display = PlatformUI.createDisplay();
183 try
184 {
185 int returnCode = PlatformUI.createAndRunWorkbench(display, workbenchAdvisor);
186 if (returnCode == PlatformUI.RETURN_RESTART)
187 {
188 return IApplication.EXIT_RESTART;
189 }
190 else
191 {
192 return IApplication.EXIT_OK;
193 }
194 }
195 finally
196 {
197 display.dispose();
198 }
199 }
200
201 /**
202 * @see org.eclipse.equinox.app.IApplication#stop()
203 * <!-- begin-user-doc -->
204 * <!-- end-user-doc -->
205 * @generated
206 */
207 <%if (genModel.useInterfaceOverrideAnnotation()){%>
208 @Override
209 <%}%>
210 public void stop()
211 {
212 // Do nothing.
213 }
214 }
215
216 /**
217 * RCP's perspective
218 * <!-- begin-user-doc -->
219 * <!-- end-user-doc -->
220 * @generated
221 */
222 public static class Perspective implements IPerspectiveFactory
223 {
224 /**
225 * Perspective ID
226 * <!-- begin-user-doc -->
227 * <!-- end-user-doc -->
228 * @generated
229 */
230 public static final String ID_PERSPECTIVE = "<%=genModel.getQualifiedEditorAdvisorClassName()%>Perspective";<%=genModel.getNonNLS()%>
231
232 /**
233 * @see org.eclipse.ui.IPerspectiveFactory#createInitialLayout(org.eclipse.ui.IPageLayout)
234 * <!-- begin-user-doc -->
235 * <!-- end-user-doc -->
236 * @generated
237 */
238 <%if (genModel.useInterfaceOverrideAnnotation()){%>
239 @Override
240 <%}%>
241 public void createInitialLayout(IPageLayout layout)
242 {
243 layout.setEditorAreaVisible(true);
244 layout.addPerspectiveShortcut(ID_PERSPECTIVE);
245
246 IFolderLayout right = layout.createFolder("right", IPageLayout.RIGHT, (float)0.66, layout.getEditorArea());<%=genModel.getNonNLS()%>
247 right.addView(IPageLayout.ID_OUTLINE);
248
249 IFolderLayout bottonRight = layout.createFolder("bottonRight", IPageLayout.BOTTOM, (float)0.60, "right");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
250 bottonRight.addView(IPageLayout.ID_PROP_SHEET);
251 }
252 }
253
254 /**
255 * RCP's window advisor
256 * <!-- begin-user-doc -->
257 * <!-- end-user-doc -->
258 * @generated
259 */
260 public static class WindowAdvisor extends WorkbenchWindowAdvisor
261 {
262 /**
263 * @see WorkbenchWindowAdvisor#WorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
264 * <!-- begin-user-doc -->
265 * <!-- end-user-doc -->
266 * @generated
267 */
268 public WindowAdvisor(IWorkbenchWindowConfigurer configurer)
269 {
270 super(configurer);
271 }
272
273 /**
274 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#preWindowOpen()
275 * <!-- begin-user-doc -->
276 * <!-- end-user-doc -->
277 * @generated
278 */
279 <%if (genModel.useClassOverrideAnnotation()) {%>
280 @Override
281 <%}%>
282 public void preWindowOpen()
283 {
284 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
285 configurer.setInitialSize(new Point(600, 450));
286 configurer.setShowCoolBar(false);
287 configurer.setShowStatusLine(true);
288 configurer.setTitle(getString("_UI_Application_title"));<%=genModel.getNonNLS()%>
289 }
290
291 /**
292 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#createActionBarAdvisor(org.eclipse.ui.application.IActionBarConfigurer)
293 * <!-- begin-user-doc -->
294 * <!-- end-user-doc -->
295 * @generated
296 */
297 <%if (genModel.useClassOverrideAnnotation()) {%>
298 @Override
299 <%}%>
300 public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer)
301 {
302 return new WindowActionBarAdvisor(configurer);
303 }
304 }
305
306 /**
307 * RCP's action bar advisor
308 * <!-- begin-user-doc -->
309 * <!-- end-user-doc -->
310 * @generated
311 */
312 public static class WindowActionBarAdvisor extends ActionBarAdvisor
313 {
314 /**
315 * @see ActionBarAdvisor#ActionBarAdvisor(org.eclipse.ui.application.IActionBarConfigurer)
316 * <!-- begin-user-doc -->
317 * <!-- end-user-doc -->
318 * @generated
319 */
320 public WindowActionBarAdvisor(IActionBarConfigurer configurer)
321 {
322 super(configurer);
323 }
324
325 /**
326 * @see org.eclipse.ui.application.ActionBarAdvisor#fillMenuBar(org.eclipse.jface.action.IMenuManager)
327 * <!-- begin-user-doc -->
328 * <!-- end-user-doc -->
329 * @generated
330 */
331 <%if (genModel.useClassOverrideAnnotation()) {%>
332 @Override
333 <%}%>
334 protected void fillMenuBar(IMenuManager menuBar)
335 {
336 IWorkbenchWindow window = getActionBarConfigurer().getWindowConfigurer().getWindow();
337 menuBar.add(createFileMenu(window));
338 menuBar.add(createEditMenu(window));
339 menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
340 menuBar.add(createWindowMenu(window));
341 menuBar.add(createHelpMenu(window));
342 }
343
344 /**
345 * Creates the 'File' menu.
346 * <!-- begin-user-doc -->
347 * <!-- end-user-doc -->
348 * @generated
349 */
350 protected IMenuManager createFileMenu(IWorkbenchWindow window)
351 {
352 IMenuManager menu = new MenuManager(getString("_UI_Menu_File_label"),<%=genModel.getNonNLS()%>
353 IWorkbenchActionConstants.M_FILE);
354 menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
355
356 IMenuManager newMenu = new MenuManager(getString("_UI_Menu_New_label"), "new");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
357 newMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
358
359 menu.add(newMenu);
360 menu.add(new Separator());
361 menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
362 menu.add(new Separator());
363 addToMenuAndRegister(menu, ActionFactory.CLOSE.create(window));
364 addToMenuAndRegister(menu, ActionFactory.CLOSE_ALL.create(window));
365 menu.add(new Separator());
366 addToMenuAndRegister(menu, ActionFactory.SAVE.create(window));
367 addToMenuAndRegister(menu, ActionFactory.SAVE_AS.create(window));
368 addToMenuAndRegister(menu, ActionFactory.SAVE_ALL.create(window));
369 menu.add(new Separator());
370 addToMenuAndRegister(menu, ActionFactory.QUIT.create(window));
371 menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
372 return menu;
373 }
374
375 /**
376 * Creates the 'Edit' menu.
377 * <!-- begin-user-doc -->
378 * <!-- end-user-doc -->
379 * @generated
380 */
381 protected IMenuManager createEditMenu(IWorkbenchWindow window)
382 {
383 IMenuManager menu = new MenuManager(getString("_UI_Menu_Edit_label"),<%=genModel.getNonNLS()%>
384 IWorkbenchActionConstants.M_EDIT);
385 menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
386
387 addToMenuAndRegister(menu, ActionFactory.UNDO.create(window));
388 addToMenuAndRegister(menu, ActionFactory.REDO.create(window));
389 menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
390 menu.add(new Separator());
391
392 addToMenuAndRegister(menu, ActionFactory.CUT.create(window));
393 addToMenuAndRegister(menu, ActionFactory.COPY.create(window));
394 addToMenuAndRegister(menu, ActionFactory.PASTE.create(window));
395 menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
396 menu.add(new Separator());
397
398 addToMenuAndRegister(menu, ActionFactory.DELETE.create(window));
399 addToMenuAndRegister(menu, ActionFactory.SELECT_ALL.create(window));
400 menu.add(new Separator());
401
402 menu.add(new GroupMarker(IWorkbenchActionConstants.ADD_EXT));
403
404 menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
405 menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
406 return menu;
407 }
408
409 /**
410 * Creates the 'Window' menu.
411 * <!-- begin-user-doc -->
412 * <!-- end-user-doc -->
413 * @generated
414 */
415 protected IMenuManager createWindowMenu(IWorkbenchWindow window)
416 {
417 IMenuManager menu = new MenuManager(getString("_UI_Menu_Window_label"),<%=genModel.getNonNLS()%>
418 IWorkbenchActionConstants.M_WINDOW);
419
420 addToMenuAndRegister(menu, ActionFactory.OPEN_NEW_WINDOW.create(window));
421 menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
422 <%if (!genModel.isRichAjaxPlatform()) {%>
423 menu.add(ContributionItemFactory.OPEN_WINDOWS.create(window));
424 <%}%>
425
426 return menu;
427 }
428
429 /**
430 * Creates the 'Help' menu.
431 * <!-- begin-user-doc -->
432 * <!-- end-user-doc -->
433 * @generated
434 */
435 protected IMenuManager createHelpMenu(IWorkbenchWindow window)
436 {
437 IMenuManager menu = new MenuManager(getString("_UI_Menu_Help_label"), IWorkbenchActionConstants.M_HELP);<%=genModel.getNonNLS()%>
438 // Welcome or intro page would go here
439 // Help contents would go here
440 // Tips and tricks page would go here
441 menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
442 menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
443 menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
444 return menu;
445 }
446
447 /**
448 * Adds the specified action to the given menu and also registers the action with the
449 * action bar configurer, in order to activate its key binding.
450 * <!-- begin-user-doc -->
451 * <!-- end-user-doc -->
452 * @generated
453 */
454 protected void addToMenuAndRegister(IMenuManager menuManager, IAction action)
455 {
456 menuManager.add(action);
457 getActionBarConfigurer().registerGlobalAction(action);
458 }
459 }
460
461 /**
462 * About action for the RCP application.
463 * <!-- begin-user-doc -->
464 * <!-- end-user-doc -->
465 * @generated
466 */
467 public static class AboutAction extends WorkbenchWindowActionDelegate
468 {
469 /**
470 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
471 * <!-- begin-user-doc -->
472 * <!-- end-user-doc -->
473 * @generated
474 */
475 <%if (genModel.useInterfaceOverrideAnnotation()){%>
476 @Override
477 <%}%>
478 public void run(IAction action)
479 {
480 MessageDialog.openInformation(getWindow().getShell(), getString("_UI_About_title"),<%=genModel.getNonNLS()%>
481 getString("_UI_About_text"));<%=genModel.getNonNLS()%>
482 }
483 }
484
485 <%if (!genModel.isRichAjaxPlatform()) {%>
486 /**
487 * Open action for the objects from the <%=genModel.getModelName()%> model.
488 * <!-- begin-user-doc -->
489 * <!-- end-user-doc -->
490 * @generated
491 */
492 public static class OpenAction extends WorkbenchWindowActionDelegate
493 {
494 /**
495 * Opens the editors for the files selected using the file dialog.
496 * <!-- begin-user-doc -->
497 * <!-- end-user-doc -->
498 * @generated
499 */
500 <%if (genModel.useInterfaceOverrideAnnotation()){%>
501 @Override
502 <%}%>
503 public void run(IAction action)
504 {
505 String[] filePaths = openFilePathDialog(getWindow().getShell(), SWT.OPEN, null);
506 if (filePaths.length > 0)
507 {
508 openEditor(getWindow().getWorkbench(), URI.createFileURI(filePaths[0]));
509 }
510 }
511 }
512 <%}%>
513
514 /**
515 * Open URI action for the objects from the <%=genModel.getModelName()%> model.
516 * <!-- begin-user-doc -->
517 * <!-- end-user-doc -->
518 * @generated
519 */
520 public static class OpenURIAction extends WorkbenchWindowActionDelegate
521 {
522 /**
523 * Opens the editors for the files selected using the LoadResourceDialog.
524 * <!-- begin-user-doc -->
525 * <!-- end-user-doc -->
526 * @generated
527 */
528 <%if (genModel.useInterfaceOverrideAnnotation()){%>
529 @Override
530 <%}%>
531 public void run(IAction action)
532 {
533 LoadResourceAction.LoadResourceDialog loadResourceDialog = new LoadResourceAction.LoadResourceDialog(getWindow().getShell());
534 if (Window.OK == loadResourceDialog.open())
535 {
536 <%if (genModel.useGenerics()) {%>
537 for (URI uri : loadResourceDialog.getURIs())
538 {
539 openEditor(getWindow().getWorkbench(), uri);
540 }
541 <%} else {%>
542 for (Iterator i = loadResourceDialog.getURIs().iterator(); i.hasNext();)
543 {
544 openEditor(getWindow().getWorkbench(), (URI)i.next());
545 }
546 <%}%>
547 }
548 }
549 }
550
551 <%if (!genModel.isRichAjaxPlatform()) {%>
552 /**
553 * <!-- begin-user-doc -->
554 * <!-- end-user-doc -->
555 * @generated
556 */
557 public static String[] openFilePathDialog(Shell shell, int style, String[] fileExtensionFilters)
558 {
559 return openFilePathDialog(shell, style, fileExtensionFilters, (style & SWT.OPEN) != 0, (style & SWT.OPEN) != 0, (style & SWT.SAVE) != 0);
560 }
561
562 /**
563 * <!-- begin-user-doc -->
564 * <!-- end-user-doc -->
565 * @generated
566 */
567 public static String[] openFilePathDialog(Shell shell, int style, String[] fileExtensionFilters, boolean includeGroupFilter, boolean includeAllFilter, boolean addExtension)
568 {
569 FileDialog fileDialog = new FileDialog(shell, style);
570 if (fileExtensionFilters == null)
571 {
572 fileExtensionFilters = FILE_EXTENSION_FILTERS;
573 }
574
575 // If requested, augment the file extension filters by adding a group of all the other filters (*.ext1;*.ext2;...)
576 // at the beginning and/or an all files wildcard (*.*) at the end.
577 //
578 includeGroupFilter &= fileExtensionFilters.length > 1;
579 int offset = includeGroupFilter ? 1 : 0;
580
581 if (includeGroupFilter || includeAllFilter)
582 {
583 int size = fileExtensionFilters.length + offset + (includeAllFilter ? 1 : 0);
584 String[] allFilters = new String[size];
585 <%=_StringBuilder%> group = includeGroupFilter ? new <%=_StringBuilder%>() : null;
586
587 for (int i = 0; i < fileExtensionFilters.length; i++)
588 {
589 if (includeGroupFilter)
590 {
591 if (i != 0)
592 {
593 group.append(';');
594 }
595 group.append(fileExtensionFilters[i]);
596 }
597 allFilters[i + offset] = fileExtensionFilters[i];
598 }
599
600 if (includeGroupFilter)
601 {
602 allFilters[0] = group.toString();
603 }
604 if (includeAllFilter)
605 {
606 allFilters[allFilters.length - 1] = "*.*";<%=genModel.getNonNLS()%>
607 }
608
609 fileDialog.setFilterExtensions(allFilters);
610 }
611 else
612 {
613 fileDialog.setFilterExtensions(fileExtensionFilters);
614 }
615 fileDialog.open();
616
617 String[] filenames = fileDialog.getFileNames();
618 String[] result = new String[filenames.length];
619 String path = fileDialog.getFilterPath() + File.separator;
620 String extension = null;
621
622 // If extension adding requested, get the dotted extension corresponding to the selected filter.
623 //
624 if (addExtension)
625 {
626 int i = fileDialog.getFilterIndex();
627 if (i != -1 && (!includeAllFilter || i != fileExtensionFilters.length))
628 {
629 i = includeGroupFilter && i == 0 ? 0 : i - offset;
630 String filter = fileExtensionFilters[i];
631 int dot = filter.lastIndexOf('.');
632 if (dot == 1 && filter.charAt(0) == '*')
633 {
634 extension = filter.substring(dot);
635 }
636 }
637 }
638
639 // Build the result by adding the selected path and, if needed, auto-appending the extension.
640 //
641 for (int i = 0; i < filenames.length; i++)
642 {
643 String filename = path + filenames[i];
644 if (extension != null)
645 {
646 int dot = filename.lastIndexOf('.');
647 if (dot == -1 || !Arrays.asList(fileExtensionFilters).contains("*" + filename.substring(dot)))<%=genModel.getNonNLS()%>
648 {
649 filename += extension;
650 }
651 }
652 result[i] = filename;
653 }
654 return result;
655 }
656 <%}%>
657
658 /**
659 * <!-- begin-user-doc -->
660 * <!-- end-user-doc -->
661 * @generated
662 */
663 public static boolean openEditor(IWorkbench workbench, URI uri)
664 {
665 IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
666 IWorkbenchPage page = workbenchWindow.getActivePage();
667
668 IEditorDescriptor editorDescriptor = EditUIUtil.getDefaultEditor(uri, null);
669 if (editorDescriptor == null)
670 {
671 MessageDialog.openError(
672 workbenchWindow.getShell(),
673 getString("_UI_Error_title"),<%=genModel.getNonNLS()%>
674 getString("_WARN_No_Editor", uri.lastSegment()));<%=genModel.getNonNLS()%>
675 return false;
676 }
677 else
678 {
679 try
680 {
681 page.openEditor(new URIEditorInput(uri), editorDescriptor.getId());
682 }
683 catch (PartInitException exception)
684 {
685 MessageDialog.openError(
686 workbenchWindow.getShell(),
687 getString("_UI_OpenEditorError_label"),<%=genModel.getNonNLS()%>
688 exception.getMessage());
689 return false;
690 }
691 }
692 return true;
693 }
694
695 /**
696 * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
697 * <!-- begin-user-doc -->
698 * <!-- end-user-doc -->
699 * @generated
700 */
701 <%if (genModel.useClassOverrideAnnotation()) {%>
702 @Override
703 <%}%>
704 public String getInitialWindowPerspectiveId()
705 {
706 return Perspective.ID_PERSPECTIVE;
707 }
708
709 /**
710 * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
711 * <!-- begin-user-doc -->
712 * <!-- end-user-doc -->
713 * @generated
714 */
715 <%if (genModel.useClassOverrideAnnotation()) {%>
716 @Override
717 <%}%>
718 public void initialize(IWorkbenchConfigurer configurer)
719 {
720 super.initialize(configurer);
721 configurer.setSaveAndRestore(true);
722 }
723
724 /**
725 * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
726 * <!-- begin-user-doc -->
727 * <!-- end-user-doc -->
728 * @generated
729 */
730 <%if (genModel.useClassOverrideAnnotation()) {%>
731 @Override
732 <%}%>
733 public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer)
734 {
735 return new WindowAdvisor(configurer);
736 }
737 }
738 <%genModel.emitSortedImports();%>