X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fui%2Factions%2FExportDocumentFolder.java;h=3956a5923bdd7b377c71ac5d14562ee2c4758d93;hp=929598402000f2e0401266b4a3fa77a7b65fb48e;hb=e34fedee69a6f7e3ef2188a70d8be60f7d179c10;hpb=0b471805f017da83d715a0d8409f53bdd009d31e diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/ExportDocumentFolder.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/ExportDocumentFolder.java index 929598402..3956a5923 100644 --- a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/ExportDocumentFolder.java +++ b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/ExportDocumentFolder.java @@ -1,114 +1,114 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.document.ui.actions; - -import java.io.File; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.DirectoryDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.simantics.DatabaseJob; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.ActionFactory; -import org.simantics.document.ui.Activator; -import org.simantics.document.ui.graphfile.FileDocumentUtil; -import org.simantics.graphfile.util.GraphFileUtil; - -/** - * Action for exporting file based documents. - * - * @author Marko Luukkainen - * - */ -public class ExportDocumentFolder implements ActionFactory { - Resource relation; - boolean useResourceNames; - - public ExportDocumentFolder(ReadGraph graph, String relationUri) throws DatabaseException { - relation = graph.getResource(relationUri); - useResourceNames = true; - } - - public ExportDocumentFolder(ReadGraph graph, String relationUri, String useResourceNames) throws DatabaseException { - relation = graph.getResource(relationUri); - this.useResourceNames = useResourceNames.equals("true"); - } - - @Override - public Runnable create(Object target) { - - if(!(target instanceof Resource)) - return null; - - final Resource resource = (Resource)target; - - return new Runnable() { - @Override - public void run() { - Shell shell = Display.getCurrent().getActiveShell(); - DirectoryDialog dialog = new DirectoryDialog(shell,SWT.SAVE); - String folderName = dialog.open(); - if (folderName == null) { - return; - } - File folder = new File(folderName); - int choice = -1; - if (folder.list().length > 0) { - MessageDialog messageDialog = new MessageDialog(shell, "Folder export", null, "Selected folder \"" + folderName + "\" is not empty.", MessageDialog.QUESTION, new String[]{"Delete and export","Overwrite","Cancel"}, 2); - choice = messageDialog.open(); - if (choice == 2) - return; - - } - ExportJob job = new ExportJob(resource, folder, choice == 0); - job.setUser(true); - job.schedule(); - - } - }; - } - - private class ExportJob extends DatabaseJob { - Resource resource; - File folder; - boolean clear = false; - public ExportJob(Resource resource,File folder, boolean clear) { - super("Export folder"); - this.resource = resource; - this.folder = folder; - this.clear = clear; - } - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - monitor.beginTask("Export folder", IProgressMonitor.UNKNOWN); - if (clear) { - GraphFileUtil.clearDirectoryStructure(folder); - monitor.worked(1); - } - FileDocumentUtil.exportDocumentFolder(resource, folder, relation, useResourceNames, monitor); - monitor.done(); - return new Status(IStatus.OK, Activator.PLUGIN_ID, "Folder exported."); - } catch (Exception e) { - monitor.done(); - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot export document folder.", e); - } - } - } -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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.document.ui.actions; + +import java.io.File; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.simantics.DatabaseJob; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.document.FileDocumentUtil; +import org.simantics.document.ui.Activator; +import org.simantics.graphfile.util.GraphFileUtil; + +/** + * Action for exporting file based documents. + * + * @author Marko Luukkainen + * + */ +public class ExportDocumentFolder implements ActionFactory { + Resource relation; + boolean useResourceNames; + + public ExportDocumentFolder(ReadGraph graph, String relationUri) throws DatabaseException { + relation = graph.getResource(relationUri); + useResourceNames = true; + } + + public ExportDocumentFolder(ReadGraph graph, String relationUri, String useResourceNames) throws DatabaseException { + relation = graph.getResource(relationUri); + this.useResourceNames = useResourceNames.equals("true"); + } + + @Override + public Runnable create(Object target) { + + if(!(target instanceof Resource)) + return null; + + final Resource resource = (Resource)target; + + return new Runnable() { + @Override + public void run() { + Shell shell = Display.getCurrent().getActiveShell(); + DirectoryDialog dialog = new DirectoryDialog(shell,SWT.SAVE); + String folderName = dialog.open(); + if (folderName == null) { + return; + } + File folder = new File(folderName); + int choice = -1; + if (folder.list().length > 0) { + MessageDialog messageDialog = new MessageDialog(shell, "Folder export", null, "Selected folder \"" + folderName + "\" is not empty.", MessageDialog.QUESTION, new String[]{"Delete and export","Overwrite","Cancel"}, 2); + choice = messageDialog.open(); + if (choice == 2) + return; + + } + ExportJob job = new ExportJob(resource, folder, choice == 0); + job.setUser(true); + job.schedule(); + + } + }; + } + + private class ExportJob extends DatabaseJob { + Resource resource; + File folder; + boolean clear = false; + public ExportJob(Resource resource,File folder, boolean clear) { + super("Export folder"); + this.resource = resource; + this.folder = folder; + this.clear = clear; + } + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + monitor.beginTask("Export folder", IProgressMonitor.UNKNOWN); + if (clear) { + GraphFileUtil.clearDirectoryStructure(folder); + monitor.worked(1); + } + FileDocumentUtil.exportDocumentFolder(resource, folder, relation, useResourceNames, monitor); + monitor.done(); + return new Status(IStatus.OK, Activator.PLUGIN_ID, "Folder exported."); + } catch (Exception e) { + monitor.done(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot export document folder.", e); + } + } + } +}