Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: df87a67874b8079492af1c71aa1898d58d2445b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
 * Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.oomph.setup.doc.user.wizard;

import org.eclipse.oomph.internal.ui.AccessUtil;
import org.eclipse.oomph.internal.ui.Capture;
import org.eclipse.oomph.setup.CompoundTask;
import org.eclipse.oomph.setup.ProductVersion;
import org.eclipse.oomph.setup.Project;
import org.eclipse.oomph.setup.ProjectCatalog;
import org.eclipse.oomph.setup.SetupTask;
import org.eclipse.oomph.setup.VariableTask;
import org.eclipse.oomph.setup.internal.core.SetupContext;
import org.eclipse.oomph.setup.internal.core.SetupTaskPerformer;
import org.eclipse.oomph.setup.p2.P2Task;
import org.eclipse.oomph.setup.ui.wizards.SetupWizard;
import org.eclipse.oomph.setup.ui.wizards.SetupWizardPage;
import org.eclipse.oomph.util.ReflectUtil;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;

import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @ignore
 */
public abstract class CaptureSetupWizard extends Capture.Window<WizardDialog>
{
  protected SetupWizard getSetupWizard(WizardDialog wizardDialog)
  {
    return (SetupWizard)wizardDialog.getCurrentPage().getWizard();
  }

  protected SetupContext getSetupContext(WizardDialog wizardDialog)
  {
    return getSetupWizard(wizardDialog).getSetupContext();
  }

  protected ResourceSet getResourceSet(WizardDialog wizardDialog)
  {
    return getSetupWizard(wizardDialog).getResourceSet();
  }

  protected SetupTaskPerformer getPerformer(WizardDialog wizardDialog)
  {
    return getSetupWizard(wizardDialog).getPerformer();
  }

  protected void advanceToNextPage(WizardDialog wizardDialog)
  {
    ((SetupWizardPage)wizardDialog.getCurrentPage()).advanceToNextPage();
  }

  protected void regressToPreviousPage(WizardDialog wizardDialog)
  {
    ReflectUtil.invokeMethod("backPressed", wizardDialog);
  }

  @SuppressWarnings("unchecked")
  protected <T extends Viewer> T getViewer(WizardDialog wizardDialog, String fieldName)
  {
    return (T)ReflectUtil.getValue(fieldName, wizardDialog.getCurrentPage());
  }

  @SuppressWarnings("unchecked")
  protected <T extends Control> T getViewerControl(WizardDialog wizardDialog, String fieldName)
  {
    return (T)getViewer(wizardDialog, fieldName).getControl();
  }

  protected void postProcessProductPage(WizardDialog wizardDialog)
  {
    getViewerControl(wizardDialog, "productViewer").setFocus();

    ResourceSet resourceSet = getResourceSet(wizardDialog);
    ProductVersion luna = (ProductVersion)resourceSet.getEObject(
        URI.createURI("index:/org.eclipse.setup#//@productCatalogs[name='org.eclipse.products']/@products[name='epp.package.standard']/@versions[name='luna']"),
        false);

    TreeViewer productViewer = getViewer(wizardDialog, "productViewer");
    productViewer.setSelection(new StructuredSelection(luna.getProduct()));

    AccessUtil.busyWait(10);

    ComboViewer versionComboViewer = getViewer(wizardDialog, "versionComboViewer");
    versionComboViewer.setSelection(new StructuredSelection(luna));

    ComboViewer poolComboViewer = getViewer(wizardDialog, "poolComboViewer");
    poolComboViewer.getCombo().select(0);

    Link link = getWidget(wizardDialog, "version");
    link.setText("<a>1.0.0 Build 1234</a>");
    link.getParent().layout(true);
  }

  protected void postProcessProjectPage(WizardDialog wizardDialog)
  {
    ResourceSet resourceSet = getResourceSet(wizardDialog);
    ProjectCatalog projectCatalog = (ProjectCatalog)resourceSet.getResource(URI.createURI("index:/org.eclipse.projects.setup"), false).getContents().get(0);

    TreeViewer projectViewer = getViewer(wizardDialog, "projectViewer");
    projectViewer.getControl().setFocus();

    for (Iterator<Project> it = projectCatalog.getProjects().iterator(); it.hasNext();)
    {
      Project project = it.next();
      String label = project.getLabel();
      if (!"Oomph".equals(label))
      {
        if (!"<User>".equals(label))
        {
          it.remove();
        }
      }
      else
      {
        projectViewer.setSelection(new StructuredSelection(project));
      }
    }

    ReflectUtil.invokeMethod(ReflectUtil.getMethod(projectViewer, "fireDoubleClick", DoubleClickEvent.class), projectViewer, (Object)null);
  }

  protected void postProcessUser(WizardDialog wizardDialog)
  {
    List<EObject> objectsToRemove = new ArrayList<EObject>();
    for (TreeIterator<EObject> it = getSetupContext(wizardDialog).getUser().eAllContents(); it.hasNext();)
    {
      EObject eObject = it.next();
      if (eObject instanceof SetupTask && !(eObject instanceof CompoundTask || eObject instanceof VariableTask))
      {
        objectsToRemove.add(eObject);
        it.prune();
      }
    }

    for (EObject eObject : objectsToRemove)
    {
      EcoreUtil.remove(eObject);
    }

  }

  protected void postProcessVariablePage(WizardDialog wizardDialog, String installationID)
  {
    postProcessUser(wizardDialog);

    ReflectUtil.setValue("save", wizardDialog.getCurrentPage(), false);
    Button showAllButton = getWidget(wizardDialog, "showAll");
    showAllButton.setSelection(true);
    showAllButton.notifyListeners(SWT.Selection, new Event());
    AccessUtil.busyWait(300);

    Text text = getWidget(wizardDialog, "installation.id.control");
    text.setText(installationID);
    text.notifyListeners(SWT.Modify, null);

    Combo combo = getWidget(wizardDialog, "git.clone.oomph.remoteURI.control");
    combo.setText("ssh://${git.user.id}@git.eclipse.org:29418/oomph/org.eclipse.oomph");
    combo.notifyListeners(SWT.Modify, null);
    AccessUtil.busyWait(100);
  }

  protected void postProcessConfirmationPage(WizardDialog wizardDialog, boolean all)
  {
    AccessUtil.busyWait(100);

    CheckboxTreeViewer taskViewer = getViewer(wizardDialog, "viewer");
    taskViewer.getControl().setFocus();

    if (all)
    {
      Button showAll = getWidget(wizardDialog, "showAllTasks");
      showAll.setSelection(true);
      showAll.notifyListeners(SWT.Selection, new Event());
    }

    Button overwrite = getWidget(wizardDialog, "overwrite");
    if (overwrite != null)
    {
      overwrite.setSelection(true);
      overwrite.notifyListeners(SWT.Selection, new Event());
      AccessUtil.busyWait(10);
    }

    {
      ITreeContentProvider provider = (ITreeContentProvider)taskViewer.getContentProvider();
      Object[] children = provider.getChildren(taskViewer.getInput());
      for (Object object : provider.getChildren(children[0]))
      {
        if (object instanceof P2Task)
        {
          taskViewer.setSelection(new StructuredSelection(object));
          break;
        }
      }
    }

    AccessUtil.busyWait(10);

    TreeViewer childrenViewer = getViewer(wizardDialog, "childrenViewer");
    childrenViewer.getControl().setFocus();

    {
      ITreeContentProvider provider = (ITreeContentProvider)childrenViewer.getContentProvider();
      Object[] children = provider.getChildren(childrenViewer.getInput());
      childrenViewer.setSelection(new StructuredSelection(children[0]));
    }

    SashForm hsash = getWidget(wizardDialog, "hsash");
    hsash.setWeights(new int[] { 12, 9 });

    SashForm vsash = getWidget(wizardDialog, "vsash");
    vsash.setWeights(new int[] { 2, 1 });

    AccessUtil.busyWait(10);
  }

  protected Image getCalloutImage(int index)
  {
    Image image = ExtendedImageRegistry.INSTANCE.getImage(URI.createPlatformPluginURI("org.eclipse.oomph.setup.doc/images/callout-" + index + ".png", false));
    return new Image(image.getDevice(), image.getImageData());
  }
}

Back to the top