Skip to content

Package: ECPHandlerHelper$2

ECPHandlerHelper$2

nameinstructionbranchcomplexitylinemethod
doExecute()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15:
16: package org.eclipse.emf.ecp.spi.ui.util;
17:
18: import java.util.ArrayList;
19: import java.util.Collection;
20: import java.util.HashSet;
21: import java.util.LinkedHashMap;
22: import java.util.List;
23: import java.util.Map;
24: import java.util.Set;
25:
26: import org.eclipse.core.runtime.CoreException;
27: import org.eclipse.core.runtime.IConfigurationElement;
28: import org.eclipse.core.runtime.Platform;
29: import org.eclipse.emf.ecore.EClass;
30: import org.eclipse.emf.ecore.EObject;
31: import org.eclipse.emf.ecore.EPackage;
32: import org.eclipse.emf.ecore.resource.Resource;
33: import org.eclipse.emf.ecp.core.ECPProject;
34: import org.eclipse.emf.ecp.core.ECPProjectManager;
35: import org.eclipse.emf.ecp.core.ECPProvider;
36: import org.eclipse.emf.ecp.core.ECPRepository;
37: import org.eclipse.emf.ecp.core.exceptions.ECPProjectWithNameExistsException;
38: import org.eclipse.emf.ecp.core.util.ECPCheckoutSource;
39: import org.eclipse.emf.ecp.core.util.ECPContainer;
40: import org.eclipse.emf.ecp.core.util.ECPProperties;
41: import org.eclipse.emf.ecp.core.util.ECPUtil;
42: import org.eclipse.emf.ecp.internal.ui.Activator;
43: import org.eclipse.emf.ecp.internal.ui.Messages;
44: import org.eclipse.emf.ecp.internal.ui.dialogs.DeleteDialog;
45: import org.eclipse.emf.ecp.internal.ui.dialogs.ProjectPropertiesDialog;
46: import org.eclipse.emf.ecp.internal.ui.dialogs.RepositoryPropertiesDialog;
47: import org.eclipse.emf.ecp.internal.ui.util.HandlerHelperUtil;
48: import org.eclipse.emf.ecp.internal.wizards.AddRepositoryWizard;
49: import org.eclipse.emf.ecp.internal.wizards.CheckoutProjectWizard;
50: import org.eclipse.emf.ecp.internal.wizards.CreateProjectWizard;
51: import org.eclipse.emf.ecp.internal.wizards.FilterModelElementWizard;
52: import org.eclipse.emf.ecp.spi.common.ui.CheckedModelClassComposite;
53: import org.eclipse.emf.ecp.spi.common.ui.SelectModelElementWizard;
54: import org.eclipse.emf.ecp.spi.common.ui.composites.SelectionComposite;
55: import org.eclipse.emf.ecp.spi.core.InternalProject;
56: import org.eclipse.emf.ecp.spi.core.InternalProvider;
57: import org.eclipse.emf.ecp.spi.core.InternalProvider.LifecycleEvent;
58: import org.eclipse.emf.ecp.ui.common.AddRepositoryComposite;
59: import org.eclipse.emf.ecp.ui.common.CheckoutProjectComposite;
60: import org.eclipse.emf.ecp.ui.common.CreateProjectComposite;
61: import org.eclipse.emf.ecp.ui.common.ECPCompositeFactory;
62: import org.eclipse.emf.ecp.ui.util.ECPModelElementOpenTester;
63: import org.eclipse.emf.ecp.ui.util.ECPModelElementOpener;
64: import org.eclipse.emf.ecp.ui.util.ECPModelElementOpenerWithContext;
65: import org.eclipse.emf.edit.command.ChangeCommand;
66: import org.eclipse.jface.dialogs.MessageDialog;
67: import org.eclipse.jface.viewers.ArrayContentProvider;
68: import org.eclipse.jface.viewers.LabelProvider;
69: import org.eclipse.jface.viewers.TreeViewer;
70: import org.eclipse.jface.window.Window;
71: import org.eclipse.jface.wizard.WizardDialog;
72: import org.eclipse.swt.graphics.Image;
73: import org.eclipse.swt.widgets.Display;
74: import org.eclipse.swt.widgets.Shell;
75: import org.eclipse.ui.dialogs.ListSelectionDialog;
76:
77: /**
78: * This is a utility class providing commonly necessary methods.
79: *
80: * @author Eugen Neufeld
81: * @since 1.4
82: */
83: public final class ECPHandlerHelper {
84:         private ECPHandlerHelper() {
85:         }
86:
87:         private static void showError(Shell shell, String title, String message) {
88:                 MessageDialog.openError(shell, title, message);
89:         }
90:
91:         /**
92:          * This method allows to checkout a list of {@link ECPCheckoutSource} into the workspace.
93:          *
94:          * @param checkoutObjects the List of {@link ECPCheckoutSource} to checkout
95:          * @param shell the {@link Shell} to use for diplaying UI
96:          */
97:         public static void checkout(final List<ECPCheckoutSource> checkoutObjects, final Shell shell) {
98:                 for (final ECPCheckoutSource checkoutSource : checkoutObjects) {
99:                         final CheckoutProjectComposite checkoutCompposite = ECPCompositeFactory
100:                                 .getCheckoutProjectComposite(checkoutSource);
101:                         final CheckoutProjectWizard wizard = new CheckoutProjectWizard();
102:                         wizard.setCompositeProvider(checkoutCompposite);
103:
104:                         final WizardDialog wd = new WizardDialog(shell, wizard);
105:
106:                         final int result = wd.open();
107:                         if (result == Window.OK) {
108:
109:                                 final String projectName = checkoutCompposite.getProjectName();
110:                                 final ECPProperties projectProperties = checkoutCompposite.getProjectProperties();
111:                                 try {
112:                                         checkoutSource.checkout(projectName, projectProperties);
113:                                 } catch (final ECPProjectWithNameExistsException ex) {
114:                                         showError(shell, "Cannot checkout project", "A project with name " + projectName //$NON-NLS-1$ //$NON-NLS-2$
115:                                                 + " already exists in the workspace."); //$NON-NLS-1$
116:                                 }
117:                         }
118:                 }
119:         }
120:
121:         /**
122:          * This helper method is used to delete model elements from a project.
123:          *
124:          * @param project the project to delete from
125:          * @param objects the model elements to delete
126:          */
127:         public static void deleteModelElement(final ECPProject project, final Collection<Object> objects) {
128:                 if (project != null) {
129:                         project.deleteElements(objects);
130:                 }
131:         }
132:
133:         /**
134:          * This method creates a new project.
135:          *
136:          * @param shell the shell for displaying the wizard
137:          * @return the created {@link ECPProject}
138:          */
139:         public static ECPProject createProject(final Shell shell) {
140:                 final List<ECPProvider> providers = new ArrayList<ECPProvider>();
141:                 for (final ECPProvider provider : ECPUtil.getECPProviderRegistry().getProviders()) {
142:                         if (provider.hasCreateProjectWithoutRepositorySupport()) {
143:                                 providers.add(provider);
144:                         }
145:                 }
146:                 if (providers.size() == 0) {
147:                         // TODO language
148:                         showError(shell, "No Provider", "Please check if a suitable provider is installed."); //$NON-NLS-1$//$NON-NLS-2$
149:                         return null;
150:                 }
151:                 final CreateProjectComposite createProjectComposite = ECPCompositeFactory.getCreateProjectComposite(providers);
152:                 final CreateProjectWizard wizard = new CreateProjectWizard();
153:                 wizard.setCompositeProvider(createProjectComposite);
154:
155:                 final WizardDialog wd = new WizardDialog(shell, wizard);
156:
157:                 final int result = wd.open();
158:                 if (result == Window.OK) {
159:                         final ECPProvider selectedProvider = createProjectComposite.getProvider();
160:                         if (selectedProvider == null) {
161:                                 showError(shell, "No project created", "Please check if a suitable provider is installed."); //$NON-NLS-1$//$NON-NLS-2$
162:                                 return null;
163:                         }
164:
165:                         final ECPProperties projectProperties = createProjectComposite.getProperties();
166:                         final String projectName = createProjectComposite.getProjectName();
167:
168:                         ECPProject project = null;
169:                         try {
170:                                 project = ECPUtil.getECPProjectManager()
171:                                         .createProject(selectedProvider, projectName, projectProperties);
172:                         } catch (final ECPProjectWithNameExistsException ex) {
173:                                 showError(shell, "No project created", "A project with name " + projectName //$NON-NLS-1$ //$NON-NLS-2$
174:                                         + " already exists in the workspace."); //$NON-NLS-1$
175:                                 return null;
176:                         }
177:                         if (project == null) {
178:                                 showError(shell, "No project created", "Please check the log."); //$NON-NLS-1$//$NON-NLS-2$
179:                                 return null;
180:                         }
181:                         ((InternalProvider) selectedProvider).handleLifecycle(project, LifecycleEvent.CREATE);
182:                         project.open();
183:                         return project;
184:                 }
185:                 return null;
186:         }
187:
188:         /**
189:          * Add a new {@link EObject} to the root of an {@link ECPProject}.
190:          *
191:          * @param ecpProject the {@link ECPProject} to add the {@link EObject} to
192:          * @param shell the {@link Shell} used to display the UI
193:          * @param open whether to open the corresponding editor or not
194:          * @return the created {@link EObject}
195:          */
196:         public static EObject addModelElement(final ECPProject ecpProject, final Shell shell, boolean open) {
197:                 final EClass newMEType = openSelectModelElementWizard(ecpProject, shell, open);
198:                 if (ecpProject != null && newMEType != null) {
199:                         // create ME
200:                         final EObject newMEInstance = createModelElementInstance(newMEType);
201:                         ecpProject.getEditingDomain().getCommandStack().execute(new ChangeCommand(newMEInstance) {
202:
203:                                 @Override
204:                                 protected void doExecute() {
205:                                         ecpProject.getContents().add(newMEInstance);
206:                                 }
207:                         });
208:                         if (open) {
209:                                 openModelElement(newMEInstance, ecpProject);
210:                         }
211:                         return newMEInstance;
212:                 }
213:                 return null;
214:         }
215:
216:         /**
217:          * @param resource the resource
218:          * @param activeShell current active shell
219:          * @param open if model element should be directly opened in an editor after it is added to project.
220:          *
221:          * @return the created model element.
222:          */
223:         public static EObject addModelElement(final Resource resource, Shell activeShell, boolean open) {
224:
225:                 final ECPProject ecpProject = ECPUtil.getECPProjectManager().getProject(resource);
226:                 if (ecpProject == null) {
227:                         return null;
228:                 }
229:                 final EClass newMEType = openSelectModelElementWizard(ecpProject, activeShell, open);
230:                 if (resource != null && newMEType != null) {
231:                         // create ME
232:                         final EObject newMEInstance = createModelElementInstance(newMEType);
233:                         ecpProject.getEditingDomain().getCommandStack().execute(new ChangeCommand(newMEInstance) {
234:
235:                                 @Override
236:                                 protected void doExecute() {
237:                                         resource.getContents().add(newMEInstance);
238:                                 }
239:                         });
240:                         if (open) {
241:                                 openModelElement(newMEInstance, ecpProject);
242:                         }
243:                         return newMEInstance;
244:                 }
245:                 return null;
246:         }
247:
248:         /**
249:          * @param newMEType
250:          * @return
251:          */
252:         private static EObject createModelElementInstance(final EClass newMEType) {
253:                 final EPackage ePackage = newMEType.getEPackage();
254:                 final EObject newMEInstance = ePackage.getEFactoryInstance().create(newMEType);
255:                 return newMEInstance;
256:         }
257:
258:         /**
259:          * @param ecpProject
260:          * @param shell
261:          * @param open
262:          * @return
263:          */
264:         private static EClass openSelectModelElementWizard(final ECPProject ecpProject, final Shell shell, boolean open) {
265:                 final SelectionComposite<TreeViewer> helper = ECPCompositeFactory.getSelectModelClassComposite(ecpProject);
266:                 final SelectModelElementWizard wizard = new SelectModelElementWizard(
267:                         Messages.NewModelElementWizardHandler_Title,
268:                         Messages.NewModelElementWizard_WizardTitle_AddModelElement,
269:                         Messages.NewModelElementWizard_PageTitle_AddModelElement,
270:                         Messages.NewModelElementWizard_PageDescription_AddModelElement);
271:                 wizard.setCompositeProvider(helper);
272:                 final WizardDialog wd = new WizardDialog(shell, wizard);
273:
274:                 final int wizardResult = wd.open();
275:                 if (wizardResult == Window.OK) {
276:                         final Object[] selection = helper.getSelection();
277:                         if (selection != null && selection.length > 0) {
278:                                 return (EClass) selection[0];
279:                         }
280:                 }
281:                 return null;
282:         }
283:
284:         /**
285:          * This method allows the user to filter the visible packages and classes.
286:          *
287:          * @param ecpProject the project to filter
288:          * @param shell the {@link Shell} to use for UI
289:          */
290:         public static void filterProjectPackages(final ECPProject ecpProject, final Shell shell) {
291:                 final Set<EPackage> ePackages = ECPUtil.getAllRegisteredEPackages();
292:
293:                 final CheckedModelClassComposite checkedModelComposite = ECPCompositeFactory
294:                         .getCheckedModelClassComposite(ePackages);
295:                 final Set<Object> initialSelectionSet = new HashSet<Object>();
296:                 initialSelectionSet.addAll(((InternalProject) ecpProject).getVisiblePackages());
297:                 initialSelectionSet.addAll(((InternalProject) ecpProject).getVisibleEClasses());
298:                 checkedModelComposite.setInitialSelection(initialSelectionSet.toArray());
299:
300:                 final FilterModelElementWizard wizard = new FilterModelElementWizard();
301:                 wizard.setCompositeProvider(checkedModelComposite);
302:                 final WizardDialog wd = new WizardDialog(shell, wizard);
303:
304:                 final int wizardResult = wd.open();
305:                 if (wizardResult == Window.OK) {
306:                         final Object[] dialogSelection = checkedModelComposite.getChecked();
307:                         final Set<EPackage> filtererdPackages = new HashSet<EPackage>();
308:                         final Set<EClass> filtererdEClasses = new HashSet<EClass>();
309:                         for (final Object object : dialogSelection) {
310:                                 if (object instanceof EPackage) {
311:                                         filtererdPackages.add((EPackage) object);
312:                                 } else if (object instanceof EClass) {
313:                                         final EClass eClass = (EClass) object;
314:                                         if (!filtererdPackages.contains(eClass.getEPackage())) {
315:                                                 filtererdEClasses.add(eClass);
316:                                         }
317:                                 }
318:                         }
319:                         ((InternalProject) ecpProject).setVisiblePackages(filtererdPackages);
320:                         ((InternalProject) ecpProject).setVisibleEClasses(filtererdEClasses);
321:                 }
322:         }
323:
324:         /**
325:          * This method created a new Repository.
326:          *
327:          * @param shell the shell for the Wizard
328:          * @return the created {@link ECPRepository}
329:          */
330:         public static ECPRepository createRepository(final Shell shell) {
331:                 final AddRepositoryComposite addRepositoryComposite = ECPCompositeFactory.getAddRepositoryComposite();
332:                 final AddRepositoryWizard wizard = new AddRepositoryWizard();
333:                 wizard.setCompositeProvider(addRepositoryComposite);
334:                 final WizardDialog wd = new WizardDialog(shell, wizard);
335:
336:                 final int wizardResult = wd.open();
337:                 if (wizardResult == Window.OK) {
338:                         final ECPRepository ecpRepository = ECPUtil.getECPRepositoryManager().addRepository(
339:                                 addRepositoryComposite.getProvider(), addRepositoryComposite.getRepositoryName(),
340:                                 addRepositoryComposite.getRepositoryLabel() == null ? "" : addRepositoryComposite.getRepositoryLabel(), //$NON-NLS-1$
341:                                 addRepositoryComposite.getRepositoryDescription() == null ? "" //$NON-NLS-1$
342:                                         : addRepositoryComposite
343:                                                 .getRepositoryDescription(),
344:                                 addRepositoryComposite.getProperties());
345:                         return ecpRepository;
346:                 }
347:                 return null;
348:         }
349:
350:         /**
351:          * This method closes/opens an array of ECPProject.
352:          *
353:          * @param closeables the {@link ECPProject}s to change the state for
354:          * @param currentType the action to do
355:          */
356:         public static void changeCloseState(ECPProject[] closeables, String currentType) {
357:                 for (final ECPProject closeable : closeables) {
358:                         if ("open".equalsIgnoreCase(currentType)) { //$NON-NLS-1$
359:                                 closeable.open();
360:                         } else if ("close".equalsIgnoreCase(currentType)) { //$NON-NLS-1$
361:                                 closeable.close();
362:                         }
363:                 }
364:         }
365:
366:         /**
367:          * Deletes the provided {@link ECPContainer} elements.
368:          *
369:          * @param deletables the List of {@link ECPContainer}s to delete
370:          * @param shell the shell to use for UI
371:          */
372:         public static void deleteHandlerHelper(List<ECPContainer> deletables, Shell shell) {
373:
374:                 if (!deletables.isEmpty()) {
375:                         final DeleteDialog dialog = new DeleteDialog(shell, deletables);
376:                         if (dialog.open() == Window.OK) {
377:                                 for (final ECPContainer deletable : deletables) {
378:                                         deletable.delete();
379:                                 }
380:                         }
381:                 }
382:         }
383:
384:         /**
385:          * Triggers the save on an {@link ECPProject}.
386:          *
387:          * @param project the project to save the changes on
388:          */
389:         public static void saveProject(ECPProject project) {
390:                 project.saveContents();
391:         }
392:
393:         /**
394:          * Resolve the a {@link ECPModelElementOpener} for the given model element.
395:          *
396:          * @param modelElement the element to find a opener for
397:          * @return a {@link ECPModelElementOpener} or null if no opener has been found
398:          *
399:          * @since 1.12
400:          */
401:         public static ECPModelElementOpener resolveElementOpener(final Object modelElement) {
402:                 if (modelElement == null) {
403:                         MessageDialog.openError(Display.getCurrent().getActiveShell(),
404:                                 Messages.ActionHelper_ErrorTitle_ElementDeleted, Messages.ActionHelper_ErrorMessage_ElementDeleted);
405:                         return null;
406:                 }
407:                 IConfigurationElement[] modelelementopener = Platform.getExtensionRegistry().getConfigurationElementsFor(
408:                         "org.eclipse.emf.ecp.ui.modelElementOpener"); //$NON-NLS-1$
409:                 ECPModelElementOpener bestCandidate = null;
410:                 int bestValue = -1;
411:                 for (final IConfigurationElement element : modelelementopener) {
412:                         modelelementopener = null;
413:                         try {
414:                                 final ECPModelElementOpener modelelementOpener = (ECPModelElementOpener) element
415:                                         .createExecutableExtension("class"); //$NON-NLS-1$
416:                                 for (final IConfigurationElement testerElement : element.getChildren()) {
417:                                         if ("staticTester".equals(testerElement.getName())) {//$NON-NLS-1$
418:                                                 final int priority = Integer.parseInt(testerElement.getAttribute("priority"));//$NON-NLS-1$
419:                                                 final String type = testerElement.getAttribute("modelElement"); //$NON-NLS-1$
420:                                                 try {
421:                                                         final Class<?> supportedClassType = HandlerHelperUtil.loadClass(testerElement
422:                                                                 .getContributor().getName(),
423:                                                                 type);
424:                                                         if (supportedClassType.isInstance(modelElement)) {
425:                                                                 if (priority > bestValue) {
426:                                                                         bestCandidate = modelelementOpener;
427:                                                                         bestValue = priority;
428:                                                                 }
429:                                                         }
430:
431:                                                 } catch (final ClassNotFoundException ex) {
432:                                                         Activator.log(ex);
433:                                                 }
434:                                         } else if ("dynamicTester".equals(testerElement.getName())) {//$NON-NLS-1$
435:                                                 final ECPModelElementOpenTester tester = (ECPModelElementOpenTester) testerElement
436:                                                         .createExecutableExtension("tester"); //$NON-NLS-1$
437:                                                 final int value = tester.isApplicable(modelElement);
438:                                                 if (value > bestValue) {
439:                                                         bestCandidate = modelelementOpener;
440:                                                         bestValue = value;
441:                                                 }
442:                                         }
443:                                 }
444:
445:                         } catch (final CoreException e) {
446:
447:                                 Activator.log(e);
448:                         }
449:                 }
450:                 return bestCandidate;
451:         }
452:
453:         /**
454:          * Open a view for the given model element.
455:          *
456:          * @param modelElement
457:          * ModelElement to open
458:          * the view that requested the open model element
459:          * @param ecpProject the {@link ECPProject} of the model element
460:          */
461:         public static void openModelElement(final Object modelElement, ECPProject ecpProject) {
462:                 openModelElement(modelElement, ecpProject, new LinkedHashMap<Object, Object>());
463:         }
464:
465:         /**
466:          * Open a view for the given model element.
467:          *
468:          * @param modelElement
469:          * ModelElement to open
470:          * the view that requested the open model element
471:          * @param ecpProject the {@link ECPProject} of the model element
472:          * @param contextMap context map
473:          * @since 1.12
474:          */
475:         public static void openModelElement(final Object modelElement, ECPProject ecpProject,
476:                 Map<Object, Object> contextMap) {
477:
478:                 final ECPModelElementOpener opener = resolveElementOpener(modelElement);
479:
480:                 // TODO: find solution
481:                 // ECPWorkspaceManager.getObserverBus().notify(ModelElementOpenObserver.class).onOpen(me, sourceView, name);
482:                 // BEGIN SUPRESS CATCH EXCEPTION
483:                 if (opener == null) {
484:                         return;
485:                 }
486:                 try {
487:                         if (opener instanceof ECPModelElementOpenerWithContext) {
488:                                 ((ECPModelElementOpenerWithContext) opener).openModelElement(modelElement, ecpProject, contextMap);
489:                         } else {
490:                                 opener.openModelElement(modelElement, ecpProject);
491:                         }
492:                 } catch (final RuntimeException e) {
493:                         Activator.log(e);
494:                 }
495:                 // END SUPRESS CATCH EXCEPTION
496:
497:         }
498:
499:         /**
500:          * Opens a Dialog showing the properties of the provided {@link ECPProject}.
501:          *
502:          * @param project the project whose properties should be shown
503:          * @param editable whether the properties should be editable
504:          * @param shell the {@link Shell} to use for the dialog
505:          */
506:         public static void openProjectProperties(ECPProject project, boolean editable, Shell shell) {
507:                 new ProjectPropertiesDialog(shell, editable, project).open();
508:         }
509:
510:         /**
511:          * Opens a Dialog showing the properties of the provided {@link ECPRepository}.
512:          *
513:          * @param repository the repository whose properties should be shown
514:          * @param editable whether the properties should be editable
515:          * @param shell the {@link Shell} to use for the dialog
516:          */
517:         public static void openRepositoryProperties(ECPRepository repository, boolean editable, Shell shell) {
518:                 new RepositoryPropertiesDialog(shell, editable, repository).open();
519:         }
520:
521:         /**
522:          * Opens a dialog to save dirty projects.
523:          *
524:          * @param shell to open the dialog in
525:          * @return if the save was triggered
526:          */
527:         public static boolean showDirtyProjectsDialog(Shell shell) {
528:                 final ECPProjectManager manager = ECPUtil.getECPProjectManager();
529:
530:                 final List<ECPProject> dirtyProjects = new ArrayList<ECPProject>();
531:                 for (final ECPProject project : manager.getProjects()) {
532:                         if (project.isOpen() && project.hasDirtyContents()) {
533:                                 dirtyProjects.add(project);
534:                         }
535:                 }
536:                 if (dirtyProjects.isEmpty()) {
537:                         return true;
538:                 }
539:                 final ListSelectionDialog lsd = new ListSelectionDialog(shell, dirtyProjects,
540:                         ArrayContentProvider.getInstance(),
541:                         new LabelProvider() {
542:
543:                                 @Override
544:                                 public Image getImage(Object element) {
545:                                         if (ECPProject.class.isInstance(element)) {
546:                                                 return Activator.getImage("icons/project_open.gif"); //$NON-NLS-1$
547:                                         }
548:                                         return super.getImage(element);
549:                                 }
550:
551:                                 @Override
552:                                 public String getText(Object element) {
553:                                         if (ECPProject.class.isInstance(element)) {
554:                                                 return ((ECPProject) element).getName();
555:                                         }
556:                                         return super.getText(element);
557:                                 }
558:
559:                         }, "Select the projects, which should be saved."); //$NON-NLS-1$
560:                 lsd.setInitialSelections(manager.getProjects().toArray());
561:                 lsd.setTitle("Unsaved Projects"); //$NON-NLS-1$
562:                 final int result = lsd.open();
563:                 if (Window.OK == result) {
564:                         for (final Object o : lsd.getResult()) {
565:                                 ECPHandlerHelper.saveProject((ECPProject) o);
566:                         }
567:                         return true;
568:                 }
569:                 return false;
570:         }
571:
572: }