use of de.janrufmonitor.repository.filter.IFilter 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.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class AbstractFilterManager method getFiltersToLabelText.
public String getFiltersToLabelText(IFilter[] f, int shorten) {
if (f != null && f.length > 0) {
boolean processedCaller = false;
StringBuffer sb = new StringBuffer();
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_limit", "label", this.getLanguage()));
for (int i = 0; i < f.length; i++) {
IFilter f1 = f[i];
if (f1.getType().equals(FilterType.CIP)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_cip", "label", this.getLanguage()));
sb.append(this.getRuntime().getCipManager().getCipLabel(((CipFilter) f1).getCip(), this.getLanguage()));
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.MSN)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_msn", "label", this.getLanguage()));
IMsn[] m = ((MsnFilter) f1).getMsn();
for (int k = 0, l = m.length; k < l; k++) {
sb.append(m[k].getMSN());
m[k].setAdditional(this.getRuntime().getMsnManager().getMsnLabel(m[k]));
if (m[k].getAdditional().length() > 0) {
sb.append(" (" + m[k].getAdditional() + ")");
}
if ((k + 1) < l)
sb.append(", ");
}
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.DATE)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
if (((DateFilter) f1).getTimeframe() == -1) {
Date d1 = ((DateFilter) f1).getDateFrom();
Date d2 = ((DateFilter) f1).getDateTo();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
sb.append("[");
sb.append(sdf.format(d2));
sb.append(" - ");
if (d1 != null)
sb.append(sdf.format(d1));
else {
sb.append(this.getI18nManager().getString(this.getNamespace(), "today", "label", this.getLanguage()));
}
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
} else {
sb.append("[");
sb.append(this.getI18nManager().getString(this.getNamespace(), Long.toString(((DateFilter) f1).getTimeframe()), "label", this.getLanguage()));
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
}
}
if (f1.getType().equals(FilterType.YEAR)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
sb.append("[");
sb.append(((YearFilter) f1).getYear());
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.MONTH_YEAR)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
sb.append("[");
sb.append(((MonthYearFilter) f1).getYear());
sb.append(".");
sb.append((((MonthYearFilter) f1).getMonth() > 9 ? ((MonthYearFilter) f1).getMonth() : "0" + ((MonthYearFilter) f1).getMonth()));
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.CALLER) && !processedCaller) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_caller", "label", this.getLanguage()));
if ((i + 1) < f.length && !processedCaller)
sb.append(", ");
processedCaller = true;
}
if (f1.getType().equals(FilterType.PHONENUMBER)) {
PhonenumberFilter cf = ((PhonenumberFilter) f1);
IPhonenumber pnc = getRuntime().getCallerFactory().createPhonenumber(cf.getPhonenumber().getIntAreaCode(), cf.getPhonenumber().getAreaCode(), "0000000000");
ICaller c = Identifier.identifyDefault(getRuntime(), pnc);
if (c != null) {
IAttribute city = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
if (city != null && city.getValue().trim().length() > 0) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_area", "label", this.getLanguage()).substring(2));
sb.append(city.getValue().trim());
sb.append(" (0");
sb.append(cf.getPhonenumber().getAreaCode());
sb.append(")");
if ((i + 1) < f.length)
sb.append(", ");
continue;
}
}
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_intarea", "label", this.getLanguage()));
sb.append("00" + cf.getPhonenumber().getIntAreaCode());
if (cf.getPhonenumber().getAreaCode().trim().length() > 0) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_area", "label", this.getLanguage()));
sb.append("0" + cf.getPhonenumber().getAreaCode().trim());
}
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.ITEMCOUNT)) {
ItemCountFilter cf = ((ItemCountFilter) f1);
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_itemcount", "label", this.getLanguage()));
sb.append(cf.getLimit());
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.ATTRIBUTE)) {
AttributeFilter cf = ((AttributeFilter) f1);
IAttributeMap m = cf.getAttributeMap();
if (m != null && m.size() > 0) {
Iterator it = m.iterator();
IAttribute a = null;
while (it.hasNext()) {
a = (IAttribute) it.next();
if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), a.getValue(), "label", this.getLanguage()));
} else if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), a.getName(), "label", this.getLanguage()));
sb.append(a.getValue());
} else {
sb.append(this.getI18nManager().getString(this.getNamespace(), a.getName(), "label", this.getLanguage()));
}
if (it.hasNext())
sb.append(", ");
}
}
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.CHARACTER)) {
CharacterFilter cf = ((CharacterFilter) f1);
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_" + cf.getAttributeName(), "label", this.getLanguage()));
sb.append("[");
sb.append(cf.getCharacter().toUpperCase());
sb.append("...]");
if ((i + 1) < f.length)
sb.append(", ");
}
}
String s = sb.toString();
if (s.trim().endsWith(","))
s = s.trim().substring(0, s.trim().length() - 1);
if (shorten > -1 && shorten < s.length()) {
return s.substring(0, Math.min(shorten, s.length())) + "...";
}
if (s.trim().length() > 0)
return s;
}
return this.getI18nManager().getString(this.getNamespace(), "view_all", "label", this.getLanguage());
}
use of de.janrufmonitor.repository.filter.IFilter 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.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class ImportAction method run.
public void run(String[] filenames) {
List ids = ImExportFactory.getInstance().getAllImporterIds(IImExporter.CALLER_MODE);
String filename = null;
for (int h = 0; h < filenames.length; h++) {
filename = filenames[h];
if (!filename.endsWith(this.m_app.getApplication().getConfiguration().getProperty(CFG_OLD_EDITOR, "cpnumber.dat"))) {
String ext = "";
for (int i = 0; i < ids.size(); i++) {
final IImExporter imp = ImExportFactory.getInstance().getImporter((String) ids.get(i));
ext = imp.getExtension();
if (ext.startsWith("*"))
ext = ext.substring(1);
if (filename.toLowerCase().endsWith(ext) && imp.getMode() == IImExporter.CALLER_MODE) {
imp.setFilename(filename);
// chedk for categorie filters
String filter = this.m_app.getApplication().getConfiguration().getProperty("filter", "");
EditorFilterManager efm = new EditorFilterManager();
final IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, "");
if (filter.length() > 0) {
String cat = null;
IFilter[] filters = efm.getFiltersFromString(filter);
for (int z = 0; z < filters.length; z++) {
if (filters[z].getType().equals(FilterType.ATTRIBUTE)) {
AttributeFilter cf = ((AttributeFilter) filters[z]);
IAttributeMap m = cf.getAttributeMap();
if (m != null && m.size() > 0) {
Iterator it = m.iterator();
IAttribute a = null;
while (it.hasNext()) {
a = (IAttribute) it.next();
if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
cat = a.getValue();
}
}
}
}
}
if (cat != null) {
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
String text = this.getI18nManager().getString(this.getNamespace(), "assigncategoryconfirm", "label", this.getLanguage());
text = StringUtils.replaceString(text, "{%1}", cat);
messageBox.setMessage(text);
if (messageBox.open() == SWT.YES) {
category.setValue(cat);
}
}
}
final String f = filename;
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
ICallerList importedCallers = (ICallerList) getRuntime().getCallerFactory().createCallerList();
if (imp.getMode() == IImExporter.CALLER_MODE) {
ImportThread ti = new ImportThread((ICallerImporter) imp, (category.getValue().length() == 0 ? null : category));
Thread t = new Thread(ti);
t.start();
while (t.isAlive()) {
if (imp instanceof ITracker) {
String text = getI18nManager().getString(getNamespace(), "importprogress2", "label", getLanguage());
text = StringUtils.replaceString(text, "{%1}", Integer.toString(((ITracker) imp).getCurrent()));
text = StringUtils.replaceString(text, "{%2}", Integer.toString(((ITracker) imp).getTotal()));
progressMonitor.beginTask(text, IProgressMonitor.UNKNOWN);
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
if (ti != null) {
importedCallers = ti.getResult();
m_app.getController().addElements(importedCallers);
}
}
if (importedCallers.size() > 0) {
progressMonitor.done();
String msg = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(importedCallers.size()));
msg = StringUtils.replaceString(msg, "{%2}", f);
PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(msg)), "Tray");
new SWTExecuter() {
protected void execute() {
m_app.updateViews(true);
}
}.start();
} else {
progressMonitor.done();
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "error", "description", getLanguage()))), "Tray");
new SWTExecuter() {
protected void execute() {
MessageDialog.openError(DisplayManager.getDefaultDisplay().getActiveShell(), getI18nManager().getString(getNamespace(), "error", "label", getLanguage()), getI18nManager().getString(getNamespace(), "error", "description", getLanguage()));
m_logger.warning("Import of data failed.");
}
}.start();
}
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
} catch (InterruptedException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (InvocationTargetException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
} else {
// do cpnumber.dat migration
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
messageBox.setMessage(this.getI18nManager().getString(this.getNamespace(), "migrationconfirm", "label", this.getLanguage()));
if (messageBox.open() == SWT.YES) {
IImExporter imp = ImExportFactory.getInstance().getImporter("OldDatFileCallerImporter");
if (imp != null && (imp instanceof OldDatFileCallerImporter)) {
((OldDatFileCallerImporter) imp).setFilename(filename);
ICallerList importedCallers = ((OldDatFileCallerImporter) imp).doImport();
if (importedCallers != null) {
final String f = filename;
this.m_app.getController().addElements(importedCallers);
String msg = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(importedCallers.size()));
msg = StringUtils.replaceString(msg, "{%2}", f);
PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(msg)), "Tray");
m_app.updateViews(true);
}
}
} else {
return;
}
}
}
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class EditorController method buildControllerData.
private void buildControllerData() {
ICallerManager cm = this._getRepository();
if (cm != null && cm.isActive() && cm.isSupported(IReadCallerRepository.class)) {
if (cm.isSupported(ISearchableCallerRepository.class)) {
this.m_data = ((ISearchableCallerRepository) cm).getCallers(new IFilter[] { this.getFilter() }, new SearchTermSeriarlizer().getSearchTermsFromString(StringUtils.urlEncode(this.m_configuration.getProperty(CFG_SEARCHTERMS, ""))));
} else {
this.m_data = ((IReadCallerRepository) cm).getCallers(this.getFilter());
}
if (this.m_data == null)
this.m_data = this.getRuntime().getCallerFactory().createCallerList();
this.doSorting();
List lastnames = new ArrayList(26);
List cities = new ArrayList(26);
List pcode = new ArrayList(9);
List countries = new ArrayList(12);
ICaller c = null;
for (int i = 0; i < this.m_data.size(); i++) {
c = this.m_data.get(i);
if (c instanceof ICaller) {
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase()))
lastnames.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase());
}
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CITY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase()))
cities.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase());
}
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase()))
pcode.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase());
}
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase()))
countries.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase());
}
}
}
Collections.sort(lastnames);
Collections.sort(cities);
Collections.sort(pcode);
Collections.sort(countries);
for (int i = 0; i < lastnames.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
}
for (int i = 0; i < cities.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
}
for (int i = 0; i < pcode.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "=" + (String) pcode.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) pcode.get(i) + ")");
}
for (int i = 0; i < countries.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
}
this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
if (this.m_data == null)
this.m_data = this.getRuntime().getCallerFactory().createCallerList();
}
Aggregations