Search in sources :

Example 1 with IFlexiProviderOperation

use of org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation in project core by jcryptool.

the class OperationsManager method saveXML.

public void saveXML() {
    FileOutputStream fos;
    try {
        root = new OperationsViewEntryRootElement();
        Iterator<IFlexiProviderOperation> it = newOperations.values().iterator();
        while (it.hasNext()) {
            root.addEntry(it.next());
        }
        document = new Document(root);
        fos = new FileOutputStream(operationsFile);
        new XMLOutputter(Format.getPrettyFormat()).output(document, fos);
    } catch (FileNotFoundException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "FileNotFoundException while attempting to write the operations.xml file", e, true);
    } catch (IOException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "IOException while attempting to write the operations.xml file", e, true);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) FileOutputStream(java.io.FileOutputStream) OperationsViewEntryRootElement(org.jcryptool.crypto.flexiprovider.operations.xml.OperationsViewEntryRootElement) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.jdom.Document) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Example 2 with IFlexiProviderOperation

use of org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation in project core by jcryptool.

the class OperationsManager method loadOperations.

private static void loadOperations() {
    File flexiprovider = new File(DirectoryService.getWorkspaceDir(), FLEXIPROVIDER_FOLDER);
    if (!flexiprovider.exists()) {
        flexiprovider.mkdir();
    }
    operationsFile = new File(flexiprovider, OPERATIONS_FILE_NAME);
    if (operationsFile != null && operationsFile.exists() && !loaded) {
        // ensure FlexiProvider is initialized
        ProviderManager2.getInstance();
        // load xml structure
        document = loadXML();
        if (document != null) {
            root = new OperationsViewEntryRootElement(document.getRootElement());
            Iterator<EntryNode> it = root.getEntryNodes().iterator();
            while (it.hasNext()) {
                IFlexiProviderOperation current = it.next();
                newOperations.put(current.getTimestamp(), current);
            }
            loaded = true;
        }
    }
}
Also used : OperationsViewEntryRootElement(org.jcryptool.crypto.flexiprovider.operations.xml.OperationsViewEntryRootElement) EntryNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode) File(java.io.File) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Example 3 with IFlexiProviderOperation

use of org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation in project core by jcryptool.

the class OperationsManager method getTreeModel.

public ITreeNode getTreeModel() {
    loadOperations();
    // $NON-NLS-1$
    ITreeNode _invisibleRoot = new TreeNode("INVISIBLE_ROOT");
    for (IFlexiProviderOperation node : newOperations.values()) {
        if (node instanceof EntryNode) {
            _invisibleRoot.addChild((EntryNode) node);
        }
    }
    return _invisibleRoot;
}
Also used : ITreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode) TreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.TreeNode) ITreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode) EntryNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Example 4 with IFlexiProviderOperation

use of org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation in project core by jcryptool.

the class OperationsManager method importOperation.

public void importOperation(String fileName) {
    try {
        // $NON-NLS-1$
        LogUtil.logInfo("1");
        IFileStore store = EFS.getStore(URIUtil.toURI(fileName));
        // $NON-NLS-1$
        LogUtil.logInfo("2");
        InputStream is = store.openInputStream(SWT.NONE, null);
        // $NON-NLS-1$
        LogUtil.logInfo("3");
        SAXBuilder sax = new SAXBuilder();
        // $NON-NLS-1$
        LogUtil.logInfo("4");
        Document doc = sax.build(is);
        // $NON-NLS-1$
        LogUtil.logInfo("5");
        is.close();
        // $NON-NLS-1$
        LogUtil.logInfo("6");
        ExportRootElement root = new ExportRootElement(doc.getRootElement());
        // $NON-NLS-1$
        LogUtil.logInfo("7");
        IFlexiProviderOperation importEntry = root.getEntryNode();
        // $NON-NLS-1$
        LogUtil.logInfo("8");
        newOperations.put(importEntry.getTimestamp(), importEntry);
        // $NON-NLS-1$
        LogUtil.logInfo("9");
        Iterator<IOperationChangedListener> it = listeners.iterator();
        while (it.hasNext()) {
            it.next().addOperation();
        }
        // $NON-NLS-1$
        LogUtil.logInfo("10");
    } catch (CoreException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "CoreException while importing an operation", e, true);
    } catch (JDOMException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "JDOMException while importing an operation", e, true);
    } catch (IOException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "IOException while importing an operation", e, false);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) CoreException(org.eclipse.core.runtime.CoreException) ExportRootElement(org.jcryptool.crypto.flexiprovider.operations.xml.ExportRootElement) InputStream(java.io.InputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Document(org.jdom.Document) IOperationChangedListener(org.jcryptool.crypto.flexiprovider.operations.ui.listeners.IOperationChangedListener) JDOMException(org.jdom.JDOMException) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Example 5 with IFlexiProviderOperation

use of org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation in project core by jcryptool.

the class ExportOperationHandler method execute.

public Object execute(ExecutionEvent event) {
    IFlexiProviderOperation descriptor = listener.getFlexiProviderOperation();
    if (descriptor != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        LogUtil.logInfo("exporting... (" + descriptor.getTimestamp() + ")");
        FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
        dialog.setFilterPath(DirectoryService.getUserHomeDir());
        dialog.setFilterExtensions(new String[] { IConstants.ALL_FILTER_EXTENSION });
        dialog.setFilterNames(new String[] { IConstants.ALL_FILTER_NAME });
        dialog.setOverwrite(true);
        String filename = dialog.open();
        if (filename != null) {
            OperationsManager.getInstance().export(descriptor.getTimestamp(), filename);
        }
    }
    return (null);
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Aggregations

IFlexiProviderOperation (org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)6 IOException (java.io.IOException)2 EntryNode (org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.EntryNode)2 OperationsViewEntryRootElement (org.jcryptool.crypto.flexiprovider.operations.xml.OperationsViewEntryRootElement)2 Document (org.jdom.Document)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 ActionCascade (org.jcryptool.actions.core.types.ActionCascade)1 ActionItem (org.jcryptool.actions.core.types.ActionItem)1 CommandInfo (org.jcryptool.core.operations.CommandInfo)1 OperationsPlugin (org.jcryptool.core.operations.OperationsPlugin)1