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