1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.desktop.ui.internal;
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;
30 public class ImportModel extends AbstractHandler {
33 public Object execute(ExecutionEvent event) throws ExecutionException {
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);
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$
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;
51 Job job = new DatabaseJob(Messages.ImportModel_DatabaseImportModel) {
54 protected IStatus run(IProgressMonitor monitor) {
55 ModelingUtils.importModel(selected);
56 return Status.OK_STATUS;