Search in sources :

Example 11 with GraphReadMethods

use of au.gov.asd.tac.constellation.graph.GraphReadMethods in project constellation by constellation-app.

the class VisualGraphTopComponent method init.

/**
 * Initialise the TopComponent state.
 */
private void init() {
    displayPanel.add(visualManager.getVisualComponent(), BorderLayout.CENTER);
    DropTargetAdapter dta = new DropTargetAdapter() {

        @Override
        public void dragEnter(DropTargetDragEvent dtde) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY);
        }

        @Override
        public void drop(DropTargetDropEvent dtde) {
            final Transferable transferable = dtde.getTransferable();
            if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                try {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY);
                    // files will be list of file which extends from object type
                    @SuppressWarnings("unchecked") final List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
                    for (final File file : files) {
                        try (final InputStream in = StringUtils.endsWithIgnoreCase(file.getName(), FileExtensionConstants.GZIP) ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file)) {
                            final RecordStore recordStore = RecordStoreUtilities.fromTsv(in);
                            PluginExecution.withPlugin(new ImportRecordFile(recordStore)).executeLater(graph);
                        }
                    }
                } catch (final UnsupportedFlavorException | IOException ex) {
                    LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
                    dtde.rejectDrop();
                }
            } else {
                dtde.rejectDrop();
            }
        }
    };
    displayPanel.setDropTarget(new DropTarget(displayPanel, DnDConstants.ACTION_COPY, dta, true));
    content.add(getActionMap());
    savable = new MySavable();
    saveAs = new MySaveAs();
    content.add(saveAs);
    content.add(graphNode.getDataObject());
    content.add(graph);
    content.add(graphNode);
    associateLookup(new AbstractLookup(content));
    setActivatedNodes(new Node[] { graphNode });
    getActionMap().put("cut-to-clipboard", new CutToClipboardAction(graphNode));
    getActionMap().put("copy-to-clipboard", new CopyToClipboardAction(graphNode));
    getActionMap().put("paste-from-clipboard", new PasteFromClipboardAction(graphNode));
    // The actions below are per-graph.
    // NetBeans creates a single instance of an action and uses it globally, which doesn't do us any good,
    // because we want to have different toggle states on different graphs, for instance.
    // Therefore, we'll ignore NetBeans and create our own per-graph action instances.
    expandCompositesAction = new ExpandAllCompositesAction(graphNode);
    contractCompositesAction = new ContractAllCompositesAction(graphNode);
    drawNodesAction = new DrawNodesAction(graphNode);
    drawConnectionsAction = new DrawConnectionsAction(graphNode);
    drawNodeLabelsAction = new DrawNodeLabelsAction(graphNode);
    drawConnectionLabelsAction = new DrawConnectionLabelsAction(graphNode);
    drawBlazesAction = new DrawBlazesAction(graphNode);
    final ButtonGroup drawButtonGroup = new ButtonGroup();
    drawLinksAction = new DrawLinksAction(graphNode, drawButtonGroup);
    drawEdgesAction = new DrawEdgesAction(graphNode, drawButtonGroup);
    drawTransactionsAction = new DrawTransactionsAction(graphNode, drawButtonGroup);
    final ButtonGroup displayModeButtonGroup = new ButtonGroup();
    display3dAction = new Toggle3DAction(graphNode, displayModeButtonGroup);
    final ButtonGroup addModeButtonGroup = new ButtonGroup();
    toggleSelectModeAction = new ToggleSelectionModeAction(graphNode, addModeButtonGroup);
    final ButtonGroup directedModeButtonGroup = new ButtonGroup();
    toggleDrawDirectedAction = new ToggleDrawDirectedAction(graphNode, directedModeButtonGroup);
    toggleGraphVisibilityAction = new ToggleGraphVisibilityAction(graphNode);
    final JToolBar sidebar = new JToolBar(SwingConstants.VERTICAL);
    sidebar.setFloatable(false);
    sidebar.setRollover(true);
    sidebar.add(display3dAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(drawLinksAction.getToolbarPresenter());
    sidebar.add(drawEdgesAction.getToolbarPresenter());
    sidebar.add(drawTransactionsAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(drawNodesAction.getToolbarPresenter());
    sidebar.add(drawConnectionsAction.getToolbarPresenter());
    sidebar.add(drawNodeLabelsAction.getToolbarPresenter());
    sidebar.add(drawConnectionLabelsAction.getToolbarPresenter());
    sidebar.add(drawBlazesAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(toggleGraphVisibilityAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(expandCompositesAction.getToolbarPresenter());
    sidebar.add(contractCompositesAction.getToolbarPresenter());
    sidebar.addSeparator();
    sidebar.add(toggleSelectModeAction.getToolbarPresenter());
    sidebar.add(toggleDrawDirectedAction.getToolbarPresenter());
    // Add this so the side bar isn't too long.
    // Without this, the side bar has a height that extends past the icons and stops other TopComponents
    // from growing past it.
    sidebar.setMinimumSize(new Dimension(0, 0));
    // Set the modification counters to whatever they are now.
    // This causes any setup changes to be ignored.
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        graphModificationCountBase = rg.getGlobalModificationCounter();
        graphModificationCount = graphModificationCountBase;
    } finally {
        rg.release();
    }
    // Initial update so that the sidebar actions are updated to match the graph.
    visualUpdate();
    this.add(sidebar, BorderLayout.WEST);
    // Listen to graph changes so we can update our modified flag. This will determine
    // whether or not we need to enable saving of the graph.
    graph.addGraphChangeListener(this);
    final InputMap keys = getInputMap(VisualGraphTopComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    final KeyStroke key = KeyStroke.getKeyStroke("Control W");
    final CloseAction ca = new CloseAction(graphNode);
    keys.put(key, ca);
    // Set the icon.
    final Schema schema = graph.getSchema();
    final Image image = getBufferedImageForSchema(schema, false);
    VisualGraphTopComponent.this.setIcon(getNebulaIcon(image));
    final UpdateComponent<GraphReadMethods> visualUpdateComponent = new UpdateComponent<GraphReadMethods>() {

        @Override
        protected boolean update(GraphReadMethods updateState) {
            visualUpdate();
            return true;
        }
    };
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAW_FLAGS));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.VISIBLE_ABOVE_THRESHOLD));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DISPLAY_MODE_3D));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAWING_MODE));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAW_DIRECTED_TRANSACTIONS));
    visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.CONNECTION_MODE));
    graphUpdateManager.setManaged(true);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) DrawConnectionsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionsAction) PasteFromClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.PasteFromClipboardAction) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) DrawTransactionsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawTransactionsAction) CutToClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CutToClipboardAction) ArrayList(java.util.ArrayList) List(java.util.List) DrawLinksAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawLinksAction) ExpandAllCompositesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ExpandAllCompositesAction) DrawNodesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodesAction) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) AbstractLookup(org.openide.util.lookup.AbstractLookup) FileInputStream(java.io.FileInputStream) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) File(java.io.File) ContractAllCompositesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ContractAllCompositesAction) CloseAction(au.gov.asd.tac.constellation.graph.interaction.plugins.io.CloseAction) DrawNodeLabelsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodeLabelsAction) GZIPInputStream(java.util.zip.GZIPInputStream) DrawEdgesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawEdgesAction) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) ToggleDrawDirectedAction(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleDrawDirectedAction) DrawConnectionLabelsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionLabelsAction) Toggle3DAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.Toggle3DAction) ToggleGraphVisibilityAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.ToggleGraphVisibilityAction) ToggleSelectionModeAction(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleSelectionModeAction) CopyToClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToClipboardAction) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Transferable(java.awt.datatransfer.Transferable) UpdateComponent(au.gov.asd.tac.constellation.plugins.update.UpdateComponent) IOException(java.io.IOException) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ButtonGroup(javax.swing.ButtonGroup) DrawBlazesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawBlazesAction)

Example 12 with GraphReadMethods

use of au.gov.asd.tac.constellation.graph.GraphReadMethods in project constellation by constellation-app.

the class AutosaveGraphPlugin method execute.

@Override
public void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final Graph graph = graphs.getGraph();
    final String graphId = graph.getId();
    final GraphNode gnode = GraphNode.getGraphNode(graphId);
    // The user might have deleted the graph, so check first.
    if (gnode != null) {
        interaction.setProgress(-1, -1, "Autosaving: " + graphId, true);
        // We don't want to hold the user up while we're reading from a graph they might be using.
        // Make a copy of the graph so that we can release the read lock as soon as possible.
        GraphReadMethods copy;
        ReadableGraph rg = graph.getReadableGraph();
        try {
            copy = rg.copy();
        } finally {
            rg.release();
        }
        interaction.setProgress(1, 0, "Finished", true);
        final File saveDir = AutosaveUtilities.getAutosaveDir();
        try {
            final String gname = graph.getId() + FileExtensionConstants.STAR;
            StatusDisplayer.getDefault().setStatusText(String.format("Auto saving %s as %s at %s...", graphId, gname, new Date()));
            final File saveFile = new File(saveDir, gname);
            new GraphJsonWriter().writeGraphToZip(copy, saveFile.getPath(), new HandleIoProgress("Autosaving..."));
            ConstellationLoggerHelper.exportPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(copy, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), saveFile, ConstellationLoggerHelper.SUCCESS);
            final Properties p = new Properties();
            p.setProperty(AutosaveUtilities.ID, graph.getId());
            p.setProperty(AutosaveUtilities.NAME, gnode.getName());
            p.setProperty(AutosaveUtilities.PATH, gnode.getDataObject().getPrimaryFile().getPath());
            p.setProperty(AutosaveUtilities.UNSAVED, Boolean.toString(gnode.getDataObject().isInMemory()));
            p.setProperty(AutosaveUtilities.DT, ZonedDateTime.now().format(TemporalFormatting.ZONED_DATE_TIME_FORMATTER));
            try (OutputStream s = new FileOutputStream(new File(saveDir, gname + "_auto"))) {
                p.store(s, null);
            }
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 13 with GraphReadMethods

use of au.gov.asd.tac.constellation.graph.GraphReadMethods in project constellation by constellation-app.

the class ByteAttributeDescriptionNGTest method testCopy.

/**
 * Test of copy method, of class ByteAttributeDescription.
 */
@Test
public void testCopy() {
    GraphReadMethods graph = new StoreGraph();
    AttributeDescription expResult = instance;
    AttributeDescription result = instance.copy(graph);
    assertEquals(result.getByte(0), expResult.getByte(0));
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 14 with GraphReadMethods

use of au.gov.asd.tac.constellation.graph.GraphReadMethods in project constellation by constellation-app.

the class DoubleAttributeDescriptionNGTest method testCopy.

/**
 * Test of copy method, of class DoubleAttributeDescription.
 */
@Test
public void testCopy() {
    GraphReadMethods graph = new StoreGraph();
    AttributeDescription expResult = instance;
    AttributeDescription result = instance.copy(graph);
    assertEquals(result.getDouble(0), expResult.getDouble(0));
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 15 with GraphReadMethods

use of au.gov.asd.tac.constellation.graph.GraphReadMethods in project constellation by constellation-app.

the class FloatAttributeDescriptionNGTest method testCopy.

/**
 * Test of copy method, of class FloatAttributeDescription.
 */
@Test
public void testCopy() {
    GraphReadMethods graph = new StoreGraph();
    AttributeDescription expResult = instance;
    AttributeDescription result = instance.copy(graph);
    assertEquals(result.getFloat(0), expResult.getFloat(0));
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Aggregations

GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)20 Test (org.testng.annotations.Test)15 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)12 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)7 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)6 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)5 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)4 Graph (au.gov.asd.tac.constellation.graph.Graph)3 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)2 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)2 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)2 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)2 MultiChoiceParameterType (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType)2