Search in sources :

Example 1 with Entry

use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.

the class CommandHistory method save.

/**
 * Save the state to an ObjectOutputStream, let someone else worry where
 * this stream came from and how to handle error / exception making sure the
 * stream is closed no matter what.
 */
private void save(ObjectOutputStream out) throws IOException {
    out.writeInt(maxSize);
    out.writeInt(size());
    for (Entry entry : history) {
        out.writeObject(entry);
    }
}
Also used : Entry(org.springsource.ide.eclipse.commons.core.Entry)

Example 2 with Entry

use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.

the class CommandHistory method load.

/**
 * Load the state from an InputOutputStream, let someone else worry where
 * this stream came from and how to handle error / exception making sure the
 * stream is closed no matter what.
 * @throws ClassNotFoundException
 * @throws IOException
 */
private void load(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int newMaxSize = in.readInt();
    Entry[] elements = new Entry[in.readInt()];
    for (int i = 0; i < elements.length; i++) {
        elements[i] = (Entry) in.readObject();
    }
    // We could do this in one go, but it is slightly nicer not to modify
    // the state of this history object until we are successful reading
    // all the elements.
    maxSize = newMaxSize;
    history = new LinkedList<Entry>();
    for (Entry element : elements) {
        history.add(element);
    }
    isDirty = false;
}
Also used : Entry(org.springsource.ide.eclipse.commons.core.Entry)

Example 3 with Entry

use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.

the class CommandHistoryTest method testSaveLoad.

public void testSaveLoad() throws Exception {
    saveFile = new File("saveit.gch");
    CommandHistory hist = new CommandHistory("test", "test", false);
    hist.add(new Entry("run-app foo", "kris"));
    assertFalse(hist.isEmpty());
    assertEquals(new Entry("run-app foo", "kris"), hist.getLast());
    hist.add(new Entry("run-app bar", "nieraj"));
    assertFalse(hist.isEmpty());
    assertEquals(new Entry("run-app bar", "nieraj"), hist.getLast());
    assertEquals(2, hist.size());
    assertTrue(hist.isDirty());
    hist.save(saveFile);
    assertFalse(hist.isDirty());
    hist = new CommandHistory("test", "test", false);
    assertTrue(hist.isEmpty());
    hist.load(saveFile);
    assertFalse(hist.isDirty());
    assertEquals(2, hist.size());
    assertIterator(hist, new Entry("run-app bar", "nieraj"), new Entry("run-app foo", "kris"));
}
Also used : CommandHistory(org.springsource.ide.eclipse.commons.internal.core.commandhistory.CommandHistory) Entry(org.springsource.ide.eclipse.commons.core.Entry) File(java.io.File)

Example 4 with Entry

use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.

the class CommandHistoryTest method testAddElements.

public void testAddElements() throws Exception {
    CommandHistory hist = new CommandHistory("test", "test", false);
    assertFalse(hist.isDirty());
    hist.add(new Entry("run-app foo", "kris"));
    assertTrue(hist.isDirty());
    assertFalse(hist.isEmpty());
    assertEquals(new Entry("run-app foo", "kris"), hist.getLast());
    hist.add(new Entry("run-app bar", "nieraj"));
    assertTrue(hist.isDirty());
    assertFalse(hist.isEmpty());
    assertEquals(new Entry("run-app bar", "nieraj"), hist.getLast());
}
Also used : CommandHistory(org.springsource.ide.eclipse.commons.internal.core.commandhistory.CommandHistory) Entry(org.springsource.ide.eclipse.commons.core.Entry)

Example 5 with Entry

use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.

the class CommandHistory method toArray.

/**
 * Returns an array of the elements in the history, with the newest item at
 * position 0.
 */
public Entry[] toArray() {
    Entry[] result = new Entry[size()];
    int i = 0;
    for (Entry entry : this) {
        result[i++] = entry;
    }
    return result;
}
Also used : Entry(org.springsource.ide.eclipse.commons.core.Entry)

Aggregations

Entry (org.springsource.ide.eclipse.commons.core.Entry)10 CommandHistory (org.springsource.ide.eclipse.commons.internal.core.commandhistory.CommandHistory)4 File (java.io.File)2 HashSet (java.util.HashSet)1 Predicate (org.apache.commons.collections.Predicate)1 FilterIterator (org.apache.commons.collections.iterators.FilterIterator)1 IProject (org.eclipse.core.resources.IProject)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Display (org.eclipse.swt.widgets.Display)1