X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.desktop.ui%2Fsrc%2Forg%2Fsimantics%2Fdesktop%2Fui%2Finternal%2FImportModel.java;h=8bb0783f317f861c345d76ca9be64732556861b0;hb=ca59190923cb45fbcde8d18d78c9c1418c1f0471;hp=42a21d76c0eebd6a1b83f401b60ba419a6d1bd7a;hpb=80950353e90c09d866b9748a0ad3ddd726d6f3b4;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java index 42a21d76c..8bb0783f3 100644 --- a/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java +++ b/bundles/org.simantics.desktop.ui/src/org/simantics/desktop/ui/internal/ImportModel.java @@ -1,67 +1,67 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.desktop.ui.internal; - -import java.io.File; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.DatabaseJob; -import org.simantics.modeling.ModelingUtils; - -public class ImportModel extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - - // Get imported transferable graph file using FileDialog - Shell shell = HandlerUtil.getActiveShellChecked(event); - FileDialog fd = new FileDialog(shell, SWT.OPEN); - fd.setText("Import Model"); - - String path = Activator.getDefault().getPreferenceStore().getString("IMPORT_MODEL_PATH"); - if(path.isEmpty() || !(new File(path).exists())){ - path = System.getProperty("user.dir"); - } - - fd.setFilterPath(path); - String[] filterExt = {"*.tg", "*.*"}; - fd.setFilterExtensions(filterExt); - final String selected = fd.open(); - if(selected == null) return null; - - Job job = new DatabaseJob("Import model") { - - @Override - protected IStatus run(IProgressMonitor monitor) { - ModelingUtils.importModel(selected); - return Status.OK_STATUS; - } - }; - - job.setUser(true); - job.schedule(); - - return null; - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.desktop.ui.internal; + +import java.io.File; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.DatabaseJob; +import org.simantics.modeling.ModelingUtils; + +public class ImportModel extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + // Get imported transferable graph file using FileDialog + Shell shell = HandlerUtil.getActiveShellChecked(event); + FileDialog fd = new FileDialog(shell, SWT.OPEN); + fd.setText(Messages.ImportModel_ImportModel); + + String path = Activator.getDefault().getPreferenceStore().getString("IMPORT_MODEL_PATH"); //$NON-NLS-1$ + if(path.isEmpty() || !(new File(path).exists())){ + path = System.getProperty("user.dir"); //$NON-NLS-1$ + } + + fd.setFilterPath(path); + String[] filterExt = {"*.tg", "*.*"}; //$NON-NLS-1$ //$NON-NLS-2$ + fd.setFilterExtensions(filterExt); + final String selected = fd.open(); + if(selected == null) return null; + + Job job = new DatabaseJob(Messages.ImportModel_DatabaseImportModel) { + + @Override + protected IStatus run(IProgressMonitor monitor) { + ModelingUtils.importModel(selected); + return Status.OK_STATUS; + } + }; + + job.setUser(true); + job.schedule(); + + return null; + + } + +}