@Override protected void doEditAction(ProcessorImpl processor) throws EditException { compoundEdit.doEdit(); }
/** * Attempts to call the doEdit method of all child edits. If any of those * children throws an EditException any successful edits are rolled back and * the exception is rethrown as the cause of a new EditException from the * CompoundEdit */ public synchronized Object doEdit() throws EditException { if (isApplied()) { throw new EditException("Cannot apply an edit more than once!"); } List<Edit<?>> doneEdits = new ArrayList<Edit<?>>(); try { for (Edit<?> edit : childEdits) { edit.doEdit(); // Insert the done edit at position 0 in the list so we can // iterate over the list in the normal order if we need to // rollback, this ensures that the most recent edit is first. doneEdits.add(0, edit); } applied = true; } catch (EditException ee) { for (Edit<?> undoMe : doneEdits) { undoMe.undo(); } applied = false; throw new EditException("Failed child of compound edit", ee); } return null; }
@Override protected void undoEditAction(ProcessorImpl processor) { compoundEdit.undo(); }
public void notify(Observable<EditManagerEvent> sender, EditManagerEvent message) throws Exception { events.add(message); if (message instanceof DataflowEditEvent) { DataflowEditEvent dataflowEdit = (DataflowEditEvent) message; assertTrue("Edit was not applied on edit event", dataflowEdit .getEdit().isApplied()); } else if (message instanceof DataFlowUndoEvent) { DataFlowUndoEvent dataflowUndo = (DataFlowUndoEvent) message; assertFalse("Edit was applied on undo event", dataflowUndo .getEdit().isApplied()); } else if (message instanceof DataFlowRedoEvent) { DataFlowRedoEvent dataflowEdit = (DataFlowRedoEvent) message; assertTrue("Edit was not applied on edit event", dataflowEdit .getEdit().isApplied()); } else { fail("Unknown event: " + message); } } }
Object subject = edit.getSubject(); if (subject instanceof Dataflow) { DataflowSelectionModel selectionModel = DataflowSelectionManager .getInstance().getDataflowSelectionModel( (Dataflow) edit.getSubject()); Object objectOfEdit = null; if (edit instanceof AddProcessorEdit) {
@Override protected void undoEditAction(ProcessorImpl processor) { compoundEdit.undo(); }
@Test public void addProcessor() throws Exception { EditManager editManager = EditManager.getInstance(); editManager.addObserver(editManagerObserver); Edits edits = editManager.getEdits(); Edit<Dataflow> edit = edits.getAddProcessorEdit(dataflow, processor); assertFalse("Edit was already applied", edit.isApplied()); assertTrue("Did already add processor", dataflow.getProcessors() .isEmpty()); editManager.doDataflowEdit(dataflow, edit); assertTrue("Edit was not applied", edit.isApplied()); assertEquals("Did not add processor", processor, dataflow .getProcessors().get(0)); // Should have received the edit event assertEquals("Incorrect number of events", 1, editManagerObserver.events.size()); EditManagerEvent event = editManagerObserver.events.get(0); assertTrue("Event was not a DataflowEditEvent", event instanceof DataflowEditEvent); DataflowEditEvent dataEditEvent = (DataflowEditEvent) event; assertEquals("Event did not have correct dataflow", dataflow, dataEditEvent.getDataFlow()); assertEquals("Event did not have correct edit", edit, dataEditEvent .getEdit()); }
private void considerEdit(EditManagerEvent message, Edit edit) { // boolean result = false; if (edit instanceof CompoundEdit) { for (Edit subEdit : ((CompoundEdit) edit).getChildEdits()) { considerEdit(message, subEdit); } } else { Object subject = edit.getSubject(); if (subject == owningProcessor) { // panel.reevaluate(); setTitle(getRelativeName(owningDataflow, activity)); } else if (subject == owningDataflow) { if (!owningDataflow.getProcessors().contains(owningProcessor)) { ActivityConfigurationAction.clearDialog(activity); } } else if (subject == activity) { if (message instanceof DataFlowUndoEvent) { logger.info("undo of activity edit found"); panel.refreshConfiguration(); } else if (message instanceof DataFlowRedoEvent) { logger.info("redo of activity edit found"); panel.refreshConfiguration(); } } } }
@Override protected void doEditAction(ProcessorImpl processor) throws EditException { compoundEdit.doEdit(); }
/** * Attempts to call the doEdit method of all child edits. If any of those * children throws an EditException any successful edits are rolled back and * the exception is rethrown as the cause of a new EditException from the * CompoundEdit */ public synchronized Object doEdit() throws EditException { if (isApplied()) { throw new EditException("Cannot apply an edit more than once!"); } List<Edit<?>> doneEdits = new ArrayList<Edit<?>>(); try { for (Edit<?> edit : childEdits) { edit.doEdit(); // Insert the done edit at position 0 in the list so we can // iterate over the list in the normal order if we need to // rollback, this ensures that the most recent edit is first. doneEdits.add(0, edit); } applied = true; } catch (EditException ee) { for (Edit<?> undoMe : doneEdits) { undoMe.undo(); } applied = false; throw new EditException("Failed child of compound edit", ee); } return null; }
/** * Rolls back all child edits in reverse order */ public synchronized void undo() { for (int i = (childEdits.size() - 1); i >= 0; i--) { // Undo child edits in reverse order childEdits.get(i).undo(); } applied = false; }
@Test public void undoAddProcessor() throws Exception { EditManager editManager = EditManager.getInstance(); editManager.addObserver(editManagerObserver); Edits edits = editManager.getEdits(); Edit<Dataflow> edit = edits.getAddProcessorEdit(dataflow, processor); editManager.doDataflowEdit(dataflow, edit); assertFalse("Did not add processor", dataflow.getProcessors().isEmpty()); editManager.undoDataflowEdit(dataflow); assertTrue("Did not undo add processor", dataflow.getProcessors() .isEmpty()); // Should have received the undo event assertEquals("Incorrect number of events", 2, editManagerObserver.events.size()); EditManagerEvent event = editManagerObserver.events.get(1); assertTrue("Event was not a DataflowEditEvent", event instanceof DataFlowUndoEvent); DataFlowUndoEvent dataEditEvent = (DataFlowUndoEvent) event; assertEquals("Event did not have correct dataflow", dataflow, dataEditEvent.getDataFlow()); assertEquals("Event did not have correct edit", edit, dataEditEvent .getEdit()); assertFalse("Edit was still applied", edit.isApplied()); }
@Override protected void undoEditAction(ProcessorImpl processor) { try { new EditsImpl().getAddProcessorOutputPortEdit(processor, port).doEdit(); } catch (EditException e) { logger.error("There was an error adding an input port to a Processor whilst undoing a remove"); } }
/** * Attempts to call the doEdit method of all child edits. If any of those * children throws an EditException any successful edits are rolled back and * the exception is rethrown as the cause of a new EditException from the * CompoundEdit */ public synchronized Object doEdit() throws EditException { if (isApplied()) { throw new EditException("Cannot apply an edit more than once!"); } List<Edit<?>> doneEdits = new ArrayList<Edit<?>>(); try { for (Edit<?> edit : childEdits) { edit.doEdit(); // Insert the done edit at position 0 in the list so we can // iterate over the list in the normal order if we need to // rollback, this ensures that the most recent edit is first. doneEdits.add(0, edit); } applied = true; } catch (EditException ee) { for (Edit<?> undoMe : doneEdits) { undoMe.undo(); } applied = false; throw new EditException("Failed child of compound edit", ee); } return null; }
@Override protected void undoEditAction(ProcessorImpl processor) { try { new EditsImpl().getAddProcessorInputPortEdit(processor, port).doEdit(); } catch (EditException e) { logger.error("There was an error adding an input port to a Processor whilst undoing a remove"); } }
/** * Check that the outgoing link to the sink port is retained when undoing a second merged input. */ @Test public void undoSecond() throws Exception { Edit<Merge> theEdit = new ConnectMergedDatalinkEdit(merge,sourcePort,sinkPort); theEdit.doEdit(); ProcessorImpl p3=new ProcessorImpl(); ProcessorOutputPortImpl sourcePort2=new ProcessorOutputPortImpl(p3,"source_port2",0,0); Edit<Merge> theEdit2 = new ConnectMergedDatalinkEdit(merge,sourcePort2,sinkPort); theEdit2.doEdit(); theEdit2.undo(); assertEquals(1,merge.getInputPorts().size()); assertEquals(1,merge.getOutputPort().getOutgoingLinks().size()); }