blob: 0835fb7143d3a35e585aa49dd308dd86574aac1d (
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
|
/******************************************************************************
* Copyright (c) 2005, 2020 Borland Software Corporation, CEA LIST, Artal
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Artem Tikhomirov (Borland) - initial API and implementation
* Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174
*****************************************************************************/
package org.eclipse.papyrus.gmf.internal.bridge.transform;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
/**
* .gmfmap to .gmfgen
*
* @author artem
*/
public class TransformToGenModelAction implements IObjectActionDelegate {
private static final int WIZARD_WIDTH_INCH = 6;
private static final int WIZARD_HEIGHT_INCH = 6;
private IWorkbenchPart myPart;
private IStructuredSelection sselection;
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
myPart = targetPart;
}
public void selectionChanged(IAction action, ISelection selection) {
final IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
sselection = structuredSelection;
}
public void run(IAction action) {
final TransformToGenModelWizard wiz = createTransformToGenModelWizard();
wiz.setWindowTitle(action.getText());
wiz.init(PlatformUI.getWorkbench(), sselection);
WizardDialog wd = new WizardDialog(getShell(), wiz);
wd.create();
Rectangle mb = getShell().getMonitor().getClientArea();
Point dpi = getShell().getDisplay().getDPI();
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
dpi = new Point(110, 110); // OSX DPI is always 72; 110 is a common value for modern LCD screens
}
int width = dpi.x * WIZARD_WIDTH_INCH;
int height = dpi.y * WIZARD_HEIGHT_INCH;
int x = mb.x + (mb.width - width) / 2;
if (x < mb.x) {
x = mb.x;
}
int y = mb.y + (mb.height - height) / 2;
if (y < mb.y) {
y = mb.y;
}
wd.getShell().setLocation(x, y);
wd.getShell().setSize(width, height);
wd.open();
}
protected TransformToGenModelWizard createTransformToGenModelWizard(){
return new TransformToGenModelWizard();
}
private Shell getShell() {
return myPart.getSite().getShell();
}
}
|