composite.setLayout(layout);
addItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
InputDialog input = new InputDialog(getSection().getShell(),
"Add new custom components package", "Please input packages which includes Tapestry custom components:",
"", null);
if (input.open() == Window.OK) {
String newBundleName = input.getValue().trim();
List<String> tmp = model.getPackageList();
if(newBundleName != null && !newBundleName.equals("")&& !tmp.contains(newBundleName)){
List<String> added = new LinkedList<String>();
model.addPackageByPath(newBundleName);
added.add(newBundleName);
// Update the model and view
if(!added.isEmpty()) {
viewer.add(added.toArray(new String[added.size()]));
markDirty();
}
}
}
}
});
removeItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean b = MessageDialog.openQuestion(getSection().getShell(), "Delete Confirm", "Are you confirm to delete this package?");
if(b){
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if(!selection.isEmpty()) {
Iterator<?> elements = selection.iterator();
List<Object> removed = new LinkedList<Object>();
while(elements.hasNext()) {
Object pkg = elements.next();
model.removePackageByPath(pkg.toString());
removed.add(pkg);
}
if(!removed.isEmpty()) {
viewer.remove(removed.toArray(new String[removed.size()]));
markDirty();
}
}
}
}
});
collectItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IEditorPart editorPart = Workbench.getInstance()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorPart != null) {
IFileEditorInput input = (IFileEditorInput) editorPart
.getEditorInput();
IFile file = input.getFile();
collectCustomComponents(file.getProject());
}
}
});