1 /*******************************************************************************
\r
2 * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.handlers.imports;
\r
14 import java.io.File;
\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 import org.simantics.sysdyn.ui.Activator;
\r
30 import org.simantics.sysdyn.ui.utils.imports.ImportUtilsUI;
\r
32 public class ImportSharedLibraryHandler extends AbstractHandler {
\r
35 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
37 // Get imported transferable graph file using FileDialog
\r
38 Shell shell = HandlerUtil.getActiveShellChecked(event);
\r
39 FileDialog fd = new FileDialog(shell, SWT.OPEN);
\r
40 fd.setText("Import Model");
\r
42 String path = Activator.getDefault().getPreferenceStore().getString(ImportUtilsUI.IMPORTMODELTPATH);
\r
43 if(path.isEmpty() || !(new File(path).exists())){
\r
44 String execDir = System.getProperty("user.dir");
\r
45 String slash = System.getProperty("file.separator");
\r
46 path = execDir + slash + "sampleModels";
\r
49 fd.setFilterPath(path);
\r
50 String[] filterExt = {"*.sharedLibrary; *.tg", "*.*"};
\r
51 fd.setFilterExtensions(filterExt);
\r
52 final String selected = fd.open();
\r
53 if(selected == null) return null;
\r
55 Job job = new DatabaseJob("Import model") {
\r
58 protected IStatus run(IProgressMonitor monitor) {
\r
59 ModelingUtils.importSharedOntology(selected);
\r
60 return Status.OK_STATUS;
\r