Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 71bc7604daa3feae1244ed237c771f4ac37533bd (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
/*
 * Copyright (c) 2015 Eike Stepper (Loehne, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.oomph.setup.presentation;

import org.eclipse.oomph.base.provider.BaseEditUtil;
import org.eclipse.oomph.base.util.EAnnotations;
import org.eclipse.oomph.setup.Installation;
import org.eclipse.oomph.setup.SetupPackage;
import org.eclipse.oomph.setup.SetupTask;
import org.eclipse.oomph.setup.internal.core.SetupContext;
import org.eclipse.oomph.setup.internal.core.util.SetupCoreUtil;
import org.eclipse.oomph.setup.ui.wizards.SetupWizard;
import org.eclipse.oomph.ui.UIUtil;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;

/**
 * @author Eike Stepper
 */
public final class EnablementAction extends Action
{
  private final Shell shell;

  private final EClass eClass;

  private final String typeText;

  private final EList<SetupTask> enablementTasks;

  private final String defaultImageKey;

  public EnablementAction(Shell shell, EClass eClass, String typeText, EList<SetupTask> enablementTasks)
  {
    this.shell = shell;
    this.eClass = eClass;
    this.typeText = typeText;
    this.enablementTasks = enablementTasks;

    defaultImageKey = SetupPackage.Literals.SETUP_TASK.isSuperTypeOf(eClass) ? "full/obj16/SetupTask" : "full/obj16/EObject"; //$NON-NLS-1$ //$NON-NLS-2$

    setText(typeText + "..."); //$NON-NLS-1$
    setToolTipText(NLS.bind(Messages.EnablementAction_tooltip, typeText));
    setImageDescriptor(SetupEditorPlugin.INSTANCE.getImageDescriptor(defaultImageKey));
  }

  public EClass getEClass()
  {
    return eClass;
  }

  public void loadImage()
  {
    URI imageURI = EAnnotations.getImageURI(eClass);
    if (imageURI != null)
    {
      final Image image = ExtendedImageRegistry.INSTANCE.getImage(BaseEditUtil.getImage(imageURI));
      setImageDescriptor(ImageDescriptor.createFromImage(image));
    }
  }

  @Override
  public void run()
  {
    EnablementDialog dialog = new EnablementDialog(shell, eClass, typeText, enablementTasks, defaultImageKey);
    if (dialog.open() == EnablementDialog.OK)
    {
      ResourceSet resourceSet = SetupCoreUtil.createResourceSet();

      SetupContext self = SetupContext.create(resourceSet);
      Installation installation = self.getInstallation();
      installation.getSetupTasks().addAll(enablementTasks);

      SetupWizard updater = new SetupWizard.Updater(self);
      updater.setTriggerName("ENABLEMENT"); //$NON-NLS-1$
      updater.openDialog(UIUtil.getShell());
    }
  }
}

Back to the top