use of de.janrufmonitor.ui.jface.application.action.IAction in project janrufmonitor by tbrandt77.
the class OpenJournalAction method getSubActions.
public IAction[] getSubActions() {
List localCallManagers = getRuntime().getCallManagerFactory().getTypedCallManagers(ILocalRepository.class);
List remoteCallManagers = getRuntime().getCallManagerFactory().getTypedCallManagers(IRemoteRepository.class);
IAction[] actions = new IAction[localCallManagers.size() + (remoteCallManagers.size() > 0 ? remoteCallManagers.size() : 0)];
for (int i = 0; i < localCallManagers.size(); i++) {
actions[i] = new LocalAction((ILocalRepository) localCallManagers.get(i));
}
if (remoteCallManagers.size() > 0)
for (int i = 0; i < remoteCallManagers.size(); i++) {
actions[i + localCallManagers.size()] = new RemoteAction((IRemoteRepository) remoteCallManagers.get(i));
}
return actions;
}
use of de.janrufmonitor.ui.jface.application.action.IAction in project janrufmonitor by tbrandt77.
the class AbstractMenuBuilder method addAction.
protected void addAction(MenuManager m, String id) {
if (id == null)
return;
if (id.startsWith(AbstractMenuBuilder.SEPARATOR_SIGN)) {
this.addSeparator(m);
return;
}
IAction a = ActionRegistry.getInstance().getAction(id, this.m_app);
if (a != null) {
if (a.hasSubActions() && a instanceof AbstractAction) {
IAction[] subActions = a.getSubActions();
if (subActions != null && subActions.length > 0) {
MenuManager subActionsMenu = new MenuManager(((AbstractAction) a).getText());
m.add(subActionsMenu);
for (int i = 0; i < subActions.length; i++) {
subActionsMenu.add((org.eclipse.jface.action.IAction) subActions[i]);
}
}
} else {
m.add((org.eclipse.jface.action.IAction) a);
this.m_logger.info("Added menu entry <" + id + "> to " + this.m_app.getID());
}
}
}
use of de.janrufmonitor.ui.jface.application.action.IAction in project janrufmonitor by tbrandt77.
the class AbstractTreeTableApplication method createContents.
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
List actions = this.getMenuBuilder().getToolbarActions();
if (this.isShowToolbar() && actions != null && actions.size() > 0 && this.getToolBarManager() != null) {
ToolBar tb = this.getToolBarManager().createControl(composite);
for (int i = 0, j = actions.size(); i < j; i++) {
final org.eclipse.jface.action.IAction a = (org.eclipse.jface.action.IAction) actions.get(i);
if (a != null && a.getImageDescriptor() != null) {
ToolItem ti = new ToolItem(tb, SWT.PUSH);
Image img = (a).getImageDescriptor().createImage();
ti.setImage(img);
ti.setText(a.getText());
if (a instanceof AbstractAction) {
ti.setText(((AbstractAction) a).getShortText());
}
ti.setToolTipText(a.getToolTipText());
ti.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
a.run();
}
});
}
}
}
addRenderBeforeTableHooks(composite);
// add filter capability
Composite line = new Composite(composite, SWT.NONE);
line.setLayout(new GridLayout(6, false));
if (this.getFilterManager() != null) {
Composite view = new Composite(line, SWT.NONE);
view.setLayout(new GridLayout(2, false));
new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "current_view", "label", this.getLanguage()));
new Label(view, SWT.NONE);
this.currentView = new Combo(view, SWT.READ_ONLY | SWT.FLAT);
this.currentView.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String filterName = currentView.getItem(currentView.getSelectionIndex());
IFilter[] selectedFilters = (IFilter[]) currentView.getData(filterName);
getApplication().getConfiguration().setProperty(CFG_FILTER, getFilterManager().getFiltersToString(selectedFilters));
getApplication().storeConfiguration();
updateViews(true);
}
});
if (getFilterAction() != null) {
Button filterAction = new Button(view, SWT.PUSH);
filterAction.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
de.janrufmonitor.ui.jface.application.action.IAction action = getFilterAction();
if (action != null)
action.run();
}
});
filterAction.setImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_FILTER_GIF));
filterAction.pack();
}
}
final de.janrufmonitor.ui.jface.application.action.IAction action = getQuickSearchAction();
if (this.isShowQuickSearch() && action != null) {
Composite view = new Composite(line, SWT.NONE);
view.setLayout(new GridLayout(2, false));
new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "label", this.getLanguage()));
new Label(view, SWT.NONE);
final Combo search = new Combo(view, SWT.FLAT);
final String empty = this.getConfiguration().getProperty(CFG_SEARCHTERMS, "");
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.minimumWidth = 300;
search.setLayoutData(gd);
search.add(empty);
final List sh = this.getSearchHistory();
for (int i = 0; i < sh.size(); i++) {
if (!empty.equalsIgnoreCase((String) sh.get(i)))
search.add((String) sh.get(i));
}
search.select(0);
search.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
action.setData(search.getText());
action.run();
}
});
search.setToolTipText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "description", this.getLanguage()));
search.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == 13) {
action.setData(search.getText());
if (!sh.contains(search.getText())) {
sh.add(search.getText());
search.add(search.getText());
}
setSearchHistory(sh);
action.run();
}
}
});
}
Tree t = new Tree(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
viewer = new TreeViewer(t);
Tree tree = ((TreeViewer) viewer).getTree();
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
tree.setHeaderVisible(true);
tree.addTreeListener(new TreeAdapter() {
public void treeExpanded(TreeEvent e) {
if (e.item != null) {
TreeItem item = (TreeItem) e.item;
TreeItem[] items = item.getItems();
for (int i = 0; i < items.length; i++) {
items[i].setBackground(item.getBackground());
items[i].setForeground(item.getForeground());
}
}
}
});
this.updateProviders();
// added drag and drop feature
if (this.getDropTargetHandler() != null) {
int operations = DND.DROP_MOVE;
Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
DropTarget target = new DropTarget(tree, operations);
target.setTransfer(types);
target.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
// A drop has occurred, copy over the data
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
getDropTargetHandler().execute((String[]) event.data);
}
});
}
FontData tableFontData = tree.getFont().getFontData()[0];
int size = Integer.parseInt(this.getConfiguration().getProperty(CFG_FONT_SIZE, "8"));
tree.setFont(this.getSizedFont(tableFontData, size, false));
AbstractMenuBuilder mb = this.getMenuBuilder();
if (mb != null)
tree.setMenu(mb.createPopupMenu(tree));
tree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.DEL) {
de.janrufmonitor.ui.jface.application.action.IAction action = getDeleteAction();
if (action != null)
action.run();
}
}
});
tree.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent e) {
de.janrufmonitor.ui.jface.application.action.IAction action = getAssignAction();
if (action != null)
action.run();
}
});
// 2006/08/02: this is a workaround: No multiple line in table possibe
Listener paintListener = new Listener() {
int name_column = getColumnNumber("name");
int address_column = getColumnNumber("address");
public void handleEvent(Event event) {
if (event.index != name_column && event.index != address_column)
return;
switch(event.type) {
case SWT.MeasureItem:
{
TreeItem item = (TreeItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
event.width = size.x;
event.height = Math.max(event.height, size.y + 7);
break;
}
case SWT.PaintItem:
{
TreeItem item = (TreeItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
int offset2 = (event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0) + 3;
event.gc.drawText(text, event.x + offset2, event.y + offset2, true);
break;
}
case SWT.EraseItem:
{
event.detail &= ~SWT.FOREGROUND;
TreeItem item = (TreeItem) event.item;
event.gc.setBackground(item.getBackground(event.index));
event.gc.setForeground(item.getForeground(event.index));
break;
}
}
}
};
tree.addListener(SWT.MeasureItem, paintListener);
tree.addListener(SWT.PaintItem, paintListener);
tree.addListener(SWT.EraseItem, paintListener);
addRenderAfterTableHooks(composite);
tree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Tree) {
TreeItem[] selectedItems = ((Tree) e.widget).getSelection();
if (selectedItems != null && selectedItems.length > 0)
lastMarkedTreeItem = ((Tree) e.widget).indexOf(selectedItems[0]);
else
lastMarkedTreeItem = -1;
}
}
});
updateViews(true);
List startupActions = this.getMenuBuilder().getStartupActions();
if (startupActions != null && startupActions.size() > 0) {
IAction a = null;
for (int i = 0, j = startupActions.size(); i < j; i++) {
a = (IAction) startupActions.get(i);
if (a != null) {
a.setApplication(this);
a.run();
}
}
}
return composite;
}
use of de.janrufmonitor.ui.jface.application.action.IAction in project janrufmonitor by tbrandt77.
the class AbstractTableApplication method createContents.
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
if (this.getMenuBuilder() != null) {
List actions = this.getMenuBuilder().getToolbarActions();
if (this.isShowToolbar() && actions != null && actions.size() > 0 && this.getToolBarManager() != null) {
ToolBar tb = this.getToolBarManager().createControl(composite);
for (int i = 0, j = actions.size(); i < j; i++) {
final org.eclipse.jface.action.IAction a = (org.eclipse.jface.action.IAction) actions.get(i);
if (a != null && a.getImageDescriptor() != null) {
ToolItem ti = new ToolItem(tb, SWT.PUSH);
Image img = (a).getImageDescriptor().createImage();
ti.setImage(img);
ti.setText(a.getText());
if (a instanceof AbstractAction) {
ti.setText(((AbstractAction) a).getShortText());
}
ti.setToolTipText(a.getToolTipText());
ti.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
a.run();
}
});
}
}
}
}
addRenderBeforeTableHooks(composite);
// add filter capability
Composite line = new Composite(composite, SWT.NONE);
line.setLayout(new GridLayout(6, false));
if (this.getFilterManager() != null && this.getConfiguration().getProperty(CFG_ENABLE_FILTER_VIEW, "true").equalsIgnoreCase("true")) {
Composite view = new Composite(line, SWT.NONE);
view.setLayout(new GridLayout(2, false));
new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "current_view", "label", this.getLanguage()));
new Label(view, SWT.NONE);
this.currentView = new Combo(view, SWT.READ_ONLY | SWT.FLAT);
this.currentView.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String filterName = currentView.getItem(currentView.getSelectionIndex());
IFilter[] selectedFilters = (IFilter[]) currentView.getData(filterName);
getApplication().getConfiguration().setProperty(CFG_FILTER, getFilterManager().getFiltersToString(selectedFilters));
getApplication().storeConfiguration();
updateViews(true);
}
});
if (getFilterAction() != null) {
Button filterAction = new Button(view, SWT.PUSH);
filterAction.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
de.janrufmonitor.ui.jface.application.action.IAction action = getFilterAction();
if (action != null)
action.run();
}
});
filterAction.setImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_FILTER_GIF));
filterAction.pack();
}
}
final de.janrufmonitor.ui.jface.application.action.IAction action = getQuickSearchAction();
if (this.isShowQuickSearch() && action != null) {
Composite view = new Composite(line, SWT.NONE);
view.setLayout(new GridLayout(2, false));
new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "label", this.getLanguage()));
new Label(view, SWT.NONE);
final Combo search = new Combo(view, SWT.FLAT);
final String empty = this.getConfiguration().getProperty(CFG_SEARCHTERMS, "");
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.minimumWidth = 300;
search.setLayoutData(gd);
search.add(empty);
final List sh = this.getSearchHistory();
for (int i = 0; i < sh.size(); i++) {
if (!empty.equalsIgnoreCase((String) sh.get(i)))
search.add((String) sh.get(i));
}
search.select(0);
search.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
action.setData(search.getText());
action.run();
}
});
search.setToolTipText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "description", this.getLanguage()));
search.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == 13) {
action.setData(search.getText());
if (!sh.contains(search.getText())) {
sh.add(search.getText());
search.add(search.getText());
}
setSearchHistory(sh);
action.run();
}
}
});
}
viewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.VIRTUAL);
final Table table = ((TableViewer) viewer).getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setHeaderVisible(true);
this.updateProviders();
// added drag and drop feature
if (this.getDropTargetHandler() != null) {
int operations = DND.DROP_MOVE;
Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
DropTarget target = new DropTarget(table, operations);
target.setTransfer(types);
target.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
// A drop has occurred, copy over the data
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
getDropTargetHandler().execute((String[]) event.data);
}
});
}
FontData tableFontData = table.getFont().getFontData()[0];
int size = Integer.parseInt(this.getConfiguration().getProperty(CFG_FONT_SIZE, "8"));
table.setFont(this.getSizedFont(tableFontData, size, false));
AbstractMenuBuilder mb = this.getMenuBuilder();
if (mb != null)
table.setMenu(mb.createPopupMenu(table));
table.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.DEL) {
de.janrufmonitor.ui.jface.application.action.IAction action = getDeleteAction();
if (action != null && action instanceof org.eclipse.jface.action.IAction && ((org.eclipse.jface.action.IAction) action).isEnabled())
action.run();
}
}
});
table.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent e) {
de.janrufmonitor.ui.jface.application.action.IAction action = getAssignAction();
if (action != null && action instanceof org.eclipse.jface.action.IAction && ((org.eclipse.jface.action.IAction) action).isEnabled())
action.run();
}
});
// 2006/08/02: this is a workaraound: No multiple line in table possibe
Listener paintListener = new Listener() {
int name_column = getColumnNumber("name");
int address_column = getColumnNumber("address");
int img_column = getColumnNumber("imagepreview");
// removed 2010/02/17: do to usability notes column is not rendered with SWT.WRAP
// int notes_column = getColumnNumber("notes");
public void handleEvent(Event event) {
if (event.index == img_column) {
TableItem it = (TableItem) event.item;
it.setText(event.index, IJAMConst.CRLF + IJAMConst.CRLF + IJAMConst.CRLF);
switch(event.type) {
case SWT.MeasureItem:
{
TableItem item = (TableItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
event.width = size.x;
event.height = Math.max(event.height, size.y + 7);
break;
}
case SWT.PaintItem:
{
TableItem item = (TableItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
int offset2 = (event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0) + 3;
event.gc.drawText(text, event.x + offset2, event.y + offset2, true);
break;
}
case SWT.EraseItem:
{
event.detail &= ~SWT.FOREGROUND;
break;
}
}
return;
}
if (event.index != name_column && event.index != address_column)
/**
*&& event.index!=notes_column
*/
return;
switch(event.type) {
case SWT.MeasureItem:
{
TableItem item = (TableItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
event.width = size.x;
event.height = Math.max(event.height, size.y + 7);
break;
}
case SWT.PaintItem:
{
TableItem item = (TableItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
int offset2 = (event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0) + 3;
event.gc.drawText(text, event.x + offset2, event.y + offset2, true);
break;
}
case SWT.EraseItem:
{
event.detail &= ~SWT.FOREGROUND;
break;
}
}
}
};
table.addListener(SWT.MeasureItem, paintListener);
table.addListener(SWT.PaintItem, paintListener);
table.addListener(SWT.EraseItem, paintListener);
// table.addListener(SWT.SetData, new Listener() {
//
// public void handleEvent(Event e) {
// TableItem item = (TableItem)e.item;
// int index = table.indexOf(item);
// item.setText("Item "+index);
//
// }
//
// });
addRenderAfterTableHooks(composite);
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Table) {
lastMarkedRow = ((Table) e.widget).getSelectionIndex();
}
}
});
updateViews(true);
if (this.getMenuBuilder() != null) {
List startupActions = this.getMenuBuilder().getStartupActions();
if (startupActions != null && startupActions.size() > 0) {
IAction a = null;
for (int i = 0, j = startupActions.size(); i < j; i++) {
a = (IAction) startupActions.get(i);
if (a != null) {
a.setApplication(this);
a.run();
}
}
}
}
return composite;
}
use of de.janrufmonitor.ui.jface.application.action.IAction in project janrufmonitor by tbrandt77.
the class ActionRegistry method getAction.
public synchronized IAction getAction(String id, IApplication app) {
String key = id + app.getID();
if (this.m_actions.containsKey(key)) {
IAction action = (IAction) this.m_actions.get(key);
action.setApplication(app);
return action;
}
String className = this.m_configuration.getProperty(PARAMETERNAME + id, "");
if (className.length() > 0) {
try {
Class classObject = Thread.currentThread().getContextClassLoader().loadClass(className);
IAction action = (IAction) classObject.newInstance();
action.setApplication(app);
action.setID(id);
this.m_actions.put(key, action);
return action;
} catch (ClassNotFoundException ex) {
this.m_logger.severe("Could not find class: " + className);
} catch (InstantiationException ex) {
this.m_logger.severe("Could not instantiate class: " + className);
} catch (IllegalAccessException ex) {
this.m_logger.severe("Could not access class: " + className);
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
return null;
}
Aggregations