]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java
merged svn revision 33114 and added desktop and help plugins
[simantics/platform.git] / bundles / org.simantics.desktop.ui / src / org / simantics / desktop / ui / internal / ImportModel.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.desktop.ui.internal;\r
13 \r
14 import java.io.File;\r
15 \r
16 import org.eclipse.core.commands.AbstractHandler;\r
17 import org.eclipse.core.commands.ExecutionEvent;\r
18 import org.eclipse.core.commands.ExecutionException;\r
19 import org.eclipse.core.runtime.IProgressMonitor;\r
20 import org.eclipse.core.runtime.IStatus;\r
21 import org.eclipse.core.runtime.Status;\r
22 import org.eclipse.core.runtime.jobs.Job;\r
23 import org.eclipse.swt.SWT;\r
24 import org.eclipse.swt.widgets.FileDialog;\r
25 import org.eclipse.swt.widgets.Shell;\r
26 import org.eclipse.ui.handlers.HandlerUtil;\r
27 import org.simantics.DatabaseJob;\r
28 import org.simantics.modeling.ModelingUtils;\r
29 \r
30 public class ImportModel extends AbstractHandler {\r
31 \r
32     @Override\r
33     public Object execute(ExecutionEvent event) throws ExecutionException {\r
34         \r
35         // Get imported transferable graph file using FileDialog\r
36         Shell shell = HandlerUtil.getActiveShellChecked(event);\r
37         FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
38         fd.setText("Import Model");\r
39 \r
40         String path = Activator.getDefault().getPreferenceStore().getString("IMPORT_MODEL_PATH");\r
41         if(path.isEmpty() || !(new File(path).exists())){\r
42                 path = System.getProperty("user.dir");\r
43         }\r
44         \r
45         fd.setFilterPath(path);\r
46         String[] filterExt = {"*.tg", "*.*"};\r
47         fd.setFilterExtensions(filterExt);\r
48         final String selected = fd.open();\r
49         if(selected == null) return null;\r
50 \r
51         Job job = new DatabaseJob("Import model") {\r
52 \r
53             @Override\r
54             protected IStatus run(IProgressMonitor monitor) {\r
55                 ModelingUtils.importModel(selected);\r
56                 return Status.OK_STATUS;\r
57             }\r
58         };\r
59         \r
60         job.setUser(true);\r
61         job.schedule();\r
62 \r
63         return null;\r
64         \r
65     }\r
66 \r
67 }\r