use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistoryPopupList method open.
/**
* Launches the Popup List, waits for an item to be selected and then closes
* the PopupList.
*
* @param rect the initial size and location of the PopupList; the dialog
* will be positioned so that it does not run off the screen and the largest
* number of items are visible
*
* @return the text of the selected item or null if no item is selected
*/
public Entry open(Rectangle rect) {
Point listSize = list.computeSize(rect.width, SWT.DEFAULT, false);
Rectangle screenSize = shell.getDisplay().getBounds();
// Position the dialog so that it does not run off the screen and the
// largest number of items are visible
int spaceBelow = spaceBelow(rect, screenSize) - 30;
int spaceAbove = spaceAbove(rect, screenSize) - 30;
int y = 0;
if (listSize.y <= spaceAbove) {
// place popup list above table cell
setAbove(true);
if (listSize.y > spaceAbove) {
listSize.y = spaceAbove;
} else {
listSize.y += 2;
}
y = rect.y - listSize.y;
} else {
// place popup list below table cell
setAbove(false);
if (listSize.y > spaceBelow) {
listSize.y = spaceBelow;
} else {
listSize.y += 2;
}
y = rect.y + rect.height;
}
// Make dialog as wide as the cell
listSize.x = rect.width;
// dialog width should not be less than minimumWidth
if (listSize.x < minimumWidth) {
listSize.x = minimumWidth;
}
// Align right side of dialog with right side of cell
int x = rect.x + rect.width - listSize.x;
shell.setBounds(x, y, listSize.x, listSize.y);
shell.open();
list.setFocus();
Display display = shell.getDisplay();
while (!shell.isDisposed() && shell.isVisible()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
Entry result = null;
if (!shell.isDisposed()) {
int selected = list.getSelectionIndex();
shell.dispose();
if (selected >= 0) {
result = entries[isAbove ? entries.length - selected - 1 : selected];
}
}
return result;
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistoryTest method assertIterator.
// public void testValidEntries() throws Exception {
// CommandHistory hist = new CommandHistory("test", "test", false);
// Entry[] entries = new Entry[] { new Entry("a", "pa"), new Entry("b",
// "pb"), new Entry("c", "pc"),
// new Entry("d", "pd") };
// for (Entry entrie : entries) {
// hist.add(entrie);
// }
// assertEquals(entries.length, hist.size());
//
// TestProject pa = new TestProject("pa");
// TestProject pc = new TestProject("pc");
//
// assertIterator(hist.validEntries() /* none */);
//
// addGrailsNature(pa);
// assertIterator(hist.validEntries(), new Entry("a", "pa"));
//
// addGrailsNature(pc);
// assertIterator(hist.validEntries(), new Entry("c", "pc"), new Entry("a",
// "pa"));
//
// TestProject pd = new TestProject("pd");
// addGrailsNature(pd);
// assertIterator(hist.validEntries(), new Entry("d", "pd"), new Entry("c",
// "pc"), new Entry("a", "pa"));
//
// TestProject pb = new TestProject("pb");
// addGrailsNature(pb);
// assertIterator(hist.validEntries(), new Entry("d", "pd"), new Entry("c",
// "pc"), new Entry("b", "pb"),
// new Entry("a", "pa"));
//
// assertIterator(hist.getRecentValid(2), new Entry("d", "pd"), new
// Entry("c", "pc"));
// }
//
// /**
// * Turn project into a Grails project.
// */
// private void addGrailsNature(TestProject testProject) throws
// CoreException {
// GroovyRuntime.addGroovyRuntime(testProject.getProject());
// testProject.addNature(GrailsNature.NATURE_ID);
// }
private void assertIterator(Iterable<Entry> hist, Entry... expected) {
int i = 0;
for (Entry entry : hist) {
assertEquals(expected[i], entry);
i++;
}
assertEquals("Too few elements in iterator", expected.length, i);
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistoryTest method testToArray.
public void testToArray() throws Exception {
Entry[] entries = new Entry[] { new Entry("run-app foo", "kris"), new Entry("run-app bar", "nieraj"), new Entry("blah blah", "ka.da.na.za") };
CommandHistory hist = new CommandHistory("test", "test", false);
assertTrue(hist.isEmpty());
for (int i = entries.length - 1; i >= 0; i--) {
hist.add(entries[i]);
}
assertTrue(Arrays.equals(entries, hist.toArray()));
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistoryTest method testLimit.
public void testLimit() throws Exception {
CommandHistory hist = new CommandHistory("test", "test", false);
// set to a sensible value
assertTrue(hist.getMaxSize() > 10);
// initially?
Entry[] entries = new Entry[] { new Entry("a", "pa"), new Entry("b", "pb"), new Entry("c", "pc"), new Entry("d", "pd") };
for (Entry entrie : entries) {
hist.add(entrie);
}
assertEquals(entries.length, hist.size());
hist.setMaxSize(2);
assertEquals(2, hist.getMaxSize());
assertEquals(2, hist.size());
assertIterator(hist, new Entry("d", "pd"), new Entry("c", "pc"));
saveFile = new File("testSave.gch");
hist.save(saveFile);
hist = new CommandHistory("test", "test", false);
// This really is a new instance
assertTrue(hist.isEmpty());
// set to a sensible value
assertTrue(hist.getMaxSize() > 10);
// initially?
hist.load(saveFile);
assertEquals(2, hist.getMaxSize());
assertIterator(hist, new Entry("d", "pd"), new Entry("c", "pc"));
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class ValidProjectFilter method iterator.
@SuppressWarnings("unchecked")
public Iterator<Entry> iterator() {
final Set<String> validProjects = new HashSet<String>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
// Test if the selected project has the given nature
if (project.isAccessible() && SpringCoreUtils.hasNature(project, natureId)) {
validProjects.add(project.getName());
}
}
return new FilterIterator(target.iterator(), new Predicate() {
public boolean evaluate(Object _entry) {
Entry entry = (Entry) _entry;
return validProjects.contains(entry.getProject());
}
});
}
Aggregations