-
Leon Ziegler authoredLeon Ziegler authored
CopyOfConvertToXMLHandler.java 3.71 KiB
package hterhors.editor.xmlconverter;
//package hterhors.editor.xmlconverter;
//
//import java.io.BufferedWriter;
//import java.io.File;
//import java.io.FileWriter;
//import java.io.IOException;
//
//import org.eclipse.core.commands.AbstractHandler;
//import org.eclipse.core.commands.ExecutionEvent;
//import org.eclipse.core.commands.ExecutionException;
//import org.eclipse.core.resources.IResource;
//import org.eclipse.core.resources.IWorkspace;
//import org.eclipse.core.resources.ResourcesPlugin;
//import org.eclipse.core.runtime.CoreException;
//import org.eclipse.core.runtime.QualifiedName;
//import org.eclipse.jface.dialogs.MessageDialog;
//import org.eclipse.swt.widgets.DirectoryDialog;
//import org.eclipse.swt.widgets.Shell;
//import org.eclipse.ui.IEditorInput;
//import org.eclipse.ui.IEditorPart;
//import org.eclipse.ui.IFileEditorInput;
//import org.eclipse.ui.contexts.IContextActivation;
//import org.eclipse.ui.contexts.IContextService;
//import org.eclipse.ui.handlers.HandlerUtil;
//import org.eclipse.ui.texteditor.ITextEditor;
//
//public class CopyOfConvertToXMLHandler extends AbstractHandler {
// private QualifiedName path = new QualifiedName("xml", "path");
//
// @Override
// public Object execute(ExecutionEvent event) throws ExecutionException {
// ITextEditor textEditor = (ITextEditor) HandlerUtil
// .getActiveEditor(event);
// HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
// IEditorInput input = HandlerUtil.getActiveEditorInput(event);
// Shell shell = HandlerUtil.getActiveShell(event);
// IResource inputResource = extractResource(textEditor);
// createOutput(shell, inputResource, textEditor.getDocumentProvider()
// .getDocument(input).get());
// return null;
// }
//
// private IResource extractResource(IEditorPart editor) {
// IEditorInput input = editor.getEditorInput();
// if (!(input instanceof IFileEditorInput))
// return null;
// return ((IFileEditorInput) input).getFile();
// }
//
// private void createOutput(Shell shell, IResource resource, String text) {
// String directory;
// boolean newDirectory = true;
// directory = getPersistentProperty(resource, path);
//
// if (directory != null && directory.length() > 0) {
// newDirectory = !(MessageDialog.openQuestion(shell, "Question",
// "Use the previous output directory?"));
// }
// if (newDirectory) {
// DirectoryDialog fileDialog = new DirectoryDialog(shell);
// IWorkspace workspace = ResourcesPlugin.getWorkspace();
// File workspaceDirectory = workspace.getRoot().getLocation()
// .toFile();
// fileDialog.setFilterPath(workspaceDirectory.getAbsolutePath());
// directory = fileDialog.open();
//
// }
// if (directory != null && directory.length() > 0) {
// setPersistentProperty(resource, path, directory);
// write(directory, text, resource.getName());
// }
// }
//
// private String getPersistentProperty(IResource res, QualifiedName qn) {
// try {
// return res.getPersistentProperty(qn);
// } catch (CoreException e) {
// return "";
// }
// }
//
// private void setPersistentProperty(IResource res, QualifiedName qn,
// String value) {
// try {
// res.setPersistentProperty(qn, value);
// } catch (CoreException e) {
// e.printStackTrace();
// }
// }
//
// private void write(String dir, String text, String name) {
// IsrFileToXmlFile converter = new IsrFileToXmlFile();
// try {
// String htmlFile = dir + "\\" + name + ".xml";
// FileWriter output = new FileWriter(htmlFile);
// BufferedWriter writer = new BufferedWriter(output);
// writer.write(converter.convertText(text));
// writer.flush();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
//}