Skip to content

Package: EMFFormsExampleInstallerWizard

EMFFormsExampleInstallerWizard

nameinstructionbranchcomplexitylinemethod
EMFFormsExampleInstallerWizard()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
addPages()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
deleteExistingProjects(IProgressMonitor)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
dispose()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getProjectPageDescription()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getProjectPageTitle()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
installExample(IProgressMonitor)
M: 16 C: 35
69%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 3 C: 9
75%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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: * Lucas Koehler- Initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.example.wizards;
15:
16: import java.util.List;
17:
18: import org.eclipse.core.commands.ExecutionException;
19: import org.eclipse.core.runtime.IProgressMonitor;
20: import org.eclipse.emf.common.ui.wizard.AbstractExampleInstallerWizard;
21: import org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard;
22: import org.eclipse.emf.common.util.Diagnostic;
23: import org.eclipse.emfforms.internal.example.wizards.ExampleWizardsPlugin;
24: import org.eclipse.jface.resource.ImageDescriptor;
25: import org.eclipse.swt.SWT;
26: import org.eclipse.swt.custom.SashForm;
27: import org.eclipse.swt.events.SelectionAdapter;
28: import org.eclipse.swt.events.SelectionEvent;
29: import org.eclipse.swt.layout.GridData;
30: import org.eclipse.swt.layout.GridLayout;
31: import org.eclipse.swt.widgets.Composite;
32: import org.eclipse.swt.widgets.Text;
33:
34: /**
35: * Wizard to create example projects in the workspace. This implementation uses a generic page title and description for
36: * the project overview page. To customize these, the following methods can be overwritten:
37: * <ul>
38: * <li>{@link #getProjectPageTitle()}</li>
39: * <li>{@link #getProjectPageDescription()}</li>
40: * </ul>
41: *
42: * @author Lucas Koehler
43: * @since 1.18
44: */
45: public class EMFFormsExampleInstallerWizard extends ExampleInstallerWizard {
46:
47:         private ExampleInstallerPage projectPage;
48:
49:         /**
50:          * The project page for the EMFFormsExampleInstallerWizard.
51:          *
52:          * @author Lucas Koehler
53:          */
54:         public class ExampleInstallerPage extends AbstractExampleInstallerWizard.ProjectPage {
55:
56:                 private final EMFFormsExampleInstallerWizard wizard;
57:
58:                 /**
59:                  * Creates a example installation wizard page.
60:                  *
61:                  * @param exampleWizard the wizard
62:                  * @param pageName the name of the page
63:                  * @param title the displayed title of the page
64:                  * @param titleImage the displayed image of the page
65:                  */
66:                 public ExampleInstallerPage(EMFFormsExampleInstallerWizard exampleWizard, String pageName, String title,
67:                         ImageDescriptor titleImage) {
68:                         super(pageName, title, titleImage);
69:                         wizard = exampleWizard;
70:                 }
71:
72:                 @Override
73:                 public void createControl(Composite parent) {
74:                         final SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
75:                         sashForm.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL));
76:
77:                         projectList = new org.eclipse.swt.widgets.List(sashForm, SWT.SINGLE | SWT.BORDER);
78:                         projectList.setLayoutData(new GridData(GridData.FILL_BOTH));
79:                         projectList.addSelectionListener(new SelectionAdapter() {
80:                                 @Override
81:                                 public void widgetSelected(SelectionEvent e) {
82:                                         itemSelected();
83:                                 }
84:                         });
85:                         projectList.setFocus();
86:
87:                         final Composite composite = new Composite(sashForm, SWT.NONE);
88:                         {
89:                                 final GridLayout layout = new GridLayout(2, false);
90:                                 final int margin = -5;
91:                                 final int spacing = 3;
92:                                 layout.marginTop = margin;
93:                                 layout.marginLeft = margin;
94:                                 layout.marginRight = margin;
95:                                 layout.marginBottom = margin;
96:                                 layout.horizontalSpacing = spacing;
97:                                 layout.verticalSpacing = spacing;
98:                                 composite.setLayout(layout);
99:                         }
100:
101:                         descriptionText = new Text(composite, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
102:                         {
103:                                 final GridData gridData = new GridData(GridData.FILL_BOTH);
104:                                 gridData.heightHint = convertHeightInCharsToPixels(2);
105:                                 gridData.grabExcessVerticalSpace = true;
106:                                 descriptionText.setLayoutData(gridData);
107:                         }
108:
109:                         final Composite buttonComposite = new Composite(composite, SWT.NONE);
110:                         buttonComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING
111:                                 | GridData.HORIZONTAL_ALIGN_END));
112:                         buttonComposite.setLayout(new GridLayout());
113:                         {
114:                                 final GridLayout layout = new GridLayout();
115:                                 final int margin = -5;
116:                                 final int spacing = 3;
117:                                 layout.marginTop = margin;
118:                                 layout.marginLeft = margin;
119:                                 layout.marginRight = margin;
120:                                 layout.marginBottom = margin;
121:                                 layout.horizontalSpacing = spacing;
122:                                 layout.verticalSpacing = spacing;
123:                                 buttonComposite.setLayout(layout);
124:                         }
125:
126:                         refresh();
127:                         sashForm.setWeights(new int[] { 70, 30 });
128:                         setControl(sashForm);
129:                 }
130:
131:                 @Override
132:                 public void refresh() {
133:                         if (wizard.getProjectDescriptors().isEmpty()) {
134:                                 setErrorMessage(ExampleWizardsPlugin.INSTANCE.getString("_UI_NoProjectError_message")); //$NON-NLS-1$
135:                                 setPageComplete(false);
136:                         } else {
137:                                 setErrorMessage(null);
138:
139:                                 int selectionIndex = projectList.getSelectionIndex();
140:                                 if (selectionIndex < 0) {
141:                                         selectionIndex = 0;
142:                                 }
143:
144:                                 projectList.removeAll();
145:                                 for (final ProjectDescriptor projectDescriptor : wizard.getProjectDescriptors()) {
146:                                         final String name = projectDescriptor.getName();
147:                                         final boolean exists = projectDescriptor.getProject().exists();
148:                                         final String item = exists
149:                                                 ? ExampleWizardsPlugin.INSTANCE.getString(
150:                                                         "_UI_ExistingProjectName_message", new String[] { name }) //$NON-NLS-1$
151:                                                 : name;
152:                                         projectList.add(item);
153:
154:                                         projectList.setData(item, projectDescriptor);
155:                                 }
156:
157:                                 if (getControl() != null) {
158:                                         projectList.setSelection(selectionIndex);
159:                                         itemSelected();
160:                                 }
161:
162:                                 setPageComplete(true);
163:                         }
164:                 }
165:
166:                 @Override
167:                 public void setVisible(boolean visible) {
168:                         if (visible &&
169:                                 projectList.getItemCount() > 0 &&
170:                                 projectList != null &&
171:                                 projectList.getSelectionCount() == 0) {
172:                                 int index = 0;
173:                                 int count = 0;
174:                                 for (final ProjectDescriptor projectDescriptor : wizard.getProjectDescriptors()) {
175:                                         if (projectDescriptor.getProject().exists()) {
176:                                                 index = count;
177:                                                 break;
178:                                         }
179:                                         count++;
180:                                 }
181:                                 projectList.select(index);
182:                                 refresh();
183:                         }
184:                         super.setVisible(visible);
185:                 }
186:
187:                 @Override
188:                 protected ProjectDescriptor getSelectedProjectDescriptor() {
189:                         return projectList.getSelectionCount() == 0 ? null
190:                                 : (ProjectDescriptor) projectList.getData(projectList.getSelection()[0]);
191:                 }
192:
193:                 @Override
194:                 protected void itemSelected() {
195:                         final ProjectDescriptor projectDescriptor = getSelectedProjectDescriptor();
196:                         if (projectDescriptor != null) {
197:                                 final boolean exists = projectDescriptor.getProject().exists();
198:
199:                                 String description = projectDescriptor.getDescription() != null ? projectDescriptor.getDescription()
200:                                         : ""; //$NON-NLS-1$
201:                                 if (exists) {
202:                                         final String existsMessage = ExampleWizardsPlugin.INSTANCE
203:                                                 .getString("_UI_ProjectExistsAlready_message"); //$NON-NLS-1$
204:                                         description = description == "" ? //$NON-NLS-1$
205:                                                 existsMessage
206:                                                 : ExampleWizardsPlugin.INSTANCE.getString(
207:                                                         "_UI_ProjectDescriptionAndExists_message", new String[] { //$NON-NLS-1$
208:                                                                 description, existsMessage });
209:                                 }
210:                                 descriptionText.setText(description);
211:                         }
212:                 }
213:
214:         }
215:
216:         @Override
217:         public void addPages() {
218:                 projectPage = new ExampleInstallerPage(this, "projectPage", getProjectPageTitle(), null); //$NON-NLS-1$
219:                 projectPage.setDescription(getProjectPageDescription());
220:                 addPage(projectPage);
221:         }
222:
223:         @Override
224:         public void dispose() {
225:                 projectPage = null;
226:                 super.dispose();
227:         }
228:
229:         /**
230:          * Returns the title for the project page that shows the projects that are to be created in the workspace.
231:          * <p>
232:          * Override this method to provide a custom page title.
233:          *
234:          * @return The project page's title
235:          */
236:         protected String getProjectPageTitle() {
237:                 return ExampleWizardsPlugin.INSTANCE.getString("_UI_ProjectPage_title"); //$NON-NLS-1$
238:         }
239:
240:         /**
241:          * Returns the description for the project page that shows the projects that are to be created in the workspace.
242:          * <p>
243:          * Override this method to provide a custom page description.
244:          *
245:          * @return The project page's description
246:          */
247:         protected String getProjectPageDescription() {
248:                 return ExampleWizardsPlugin.INSTANCE.getString("_UI_ProjectPage_description"); //$NON-NLS-1$
249:         }
250:
251:         /**
252:          * The EMFFormsExampleInstallerWizard doesn't delete any projects.
253:          *
254:          * @param monitor progress monitor
255:          * @return OK
256:          */
257:         @Override
258:         protected Diagnostic deleteExistingProjects(IProgressMonitor monitor) {
259:                 return Diagnostic.OK_INSTANCE;
260:         }
261:
262:         /**
263:          * In contrast to the {@link AbstractExampleInstallerWizard}, the EMFFormsExampleInstallerWizard only installs
264:          * projects if
265:          * they do not already exist in the workspace.
266:          *
267:          * @param progressMonitor the progress monitor
268:          * @throws ExecutionException if something goes wrong while installing the example.
269:          * @see org.eclipse.emf.common.ui.wizard.AbstractExampleInstallerWizard#installExample(org.eclipse.core.runtime.IProgressMonitor)
270:          */
271:         @Override
272:         protected void installExample(IProgressMonitor progressMonitor) throws ExecutionException {
273:                 final List<ProjectDescriptor> projectDescriptors = getProjectDescriptors();
274:                 progressMonitor.beginTask(ExampleWizardsPlugin.INSTANCE.getString("_UI_CreatingProjects_message"), //$NON-NLS-1$
275:                         2 * projectDescriptors.size());
276:•                for (final ProjectDescriptor projectDescriptor : projectDescriptors) {
277:•                        if (!projectDescriptor.getProject().exists()) {
278:                                 try {
279:                                         installProject(projectDescriptor, progressMonitor);
280:                                 }
281:                                 // BEGIN SUPRESS CATCH EXCEPTION
282:                                 catch (final Exception ex) {
283:                                         throw new ExecutionException("The project '" + projectDescriptor.getName() //$NON-NLS-1$
284:                                                 + "' could not be installed.", ex); //$NON-NLS-1$
285:                                 }
286:                                 // END SUPRESS CATCH EXCEPTION
287:                         }
288:                 }
289:                 progressMonitor.done();
290:         }
291: }