Skip to main content
summaryrefslogtreecommitdiffstats
blob: c10f9f18b1ec8255820dd4795299fff8f116e670 (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
/*******************************************************************************
 * Copyright (c) 2016-2018 Thales Global Services S.A.S.
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Abel Hegedus, Tamas Borbas, Peter Lunk (IncQuery Labs Ltd.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.diffmerge.patch.ui.handlers

import org.eclipse.emf.diffmerge.patch.ui.utils.DialogFactory
import org.eclipse.emf.diffmerge.patch.ui.wizards.ModelpatchApplicationWizard
import org.eclipse.core.commands.AbstractHandler
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.core.commands.ExecutionException
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.jface.viewers.IStructuredSelection
import org.eclipse.jface.wizard.WizardDialog
import org.eclipse.swt.widgets.Shell
import org.eclipse.ui.handlers.HandlerUtil

class ModelpatchApplicationHandler extends AbstractHandler {
  public static val ID = "org.eclipse.emf.diffmerge.patch"

  Shell shell

  override Object execute(ExecutionEvent event) throws ExecutionException {
    try {
      shell = HandlerUtil.getActiveShell(event)
      (HandlerUtil.getCurrentSelection(event) as IStructuredSelection).executePatch
    } catch (Exception ex) {
      val factory = new DialogFactory(shell)
      factory.openErrorDialog("Modelpatch Application Problem", "Patch cannot be applied!", ex, ID)
      ex.printStackTrace
    }
    return null
  }

  private dispatch def void executePatch(IStructuredSelection strucSelection) {
    strucSelection.firstElement.executePatch
  }

  private dispatch def void executePatch(EObject eobj) {
    eobj.eResource.executePatch
  }

  private dispatch def void executePatch(Resource resource) {
    // Show ModelpatchApplicationWizard for patch file and filters
    val wizard = new WizardDialog(shell, new ModelpatchApplicationWizard(resource))
    wizard.open
  }
}

Back to the top