]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/MigrateComponentType.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / MigrateComponentType.java
1 package org.simantics.modeling.ui.actions;
2
3 import org.eclipse.jface.wizard.WizardDialog;
4 import org.eclipse.swt.widgets.Display;
5 import org.eclipse.ui.IWorkbenchWindow;
6 import org.eclipse.ui.PlatformUI;
7 import org.simantics.Simantics;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.utils.Logger;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.adapter.ActionFactory;
12 import org.simantics.db.layer0.request.PossibleURI;
13 import org.simantics.modeling.ui.wizard.MigrateWizard;
14
15 /**
16  * @author Antti Villberg
17  */
18 public class MigrateComponentType implements ActionFactory {
19
20     @Override
21     public Runnable create(Object target) {
22         
23         if (!(target instanceof Resource))
24             return null;
25         
26         final Resource r = (Resource)target;
27
28         return new Runnable() {
29
30                         @Override
31                         public void run() {
32                                 
33                                 try {
34                                         
35                                         final String initial = Simantics.sync(new PossibleURI(r));
36         
37                                         Display.getDefault().asyncExec(new Runnable() {
38
39                                                 @Override
40                                                 public void run() {
41                                                         
42                                         final int SIZING_WIZARD_WIDTH  = 500;
43                                         final int SIZING_WIZARD_HEIGHT = 600;
44                                         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
45                                         MigrateWizard wizard = new MigrateWizard(initial);
46                                         WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
47                                         dialog.create();
48                                         dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT);
49                                         dialog.open();
50                                                         
51                                                 }
52                                                 
53                                         });
54                                         
55                                 } catch (DatabaseException e) {
56                                         Logger.defaultLogError(e);
57                                 }
58                                 
59                         }
60                 
61         };
62         
63     }
64
65 }