use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class AbstractTreeTableApplication method updateViews.
public synchronized void updateViews(Object[] controllerdata, boolean reload) {
// refresh controll data
refreshController(reload);
if (controllerdata != null)
this.m_controller.generateElementArray(controllerdata);
final IFilterManager fm = this.getFilterManager();
if (fm != null) {
IFilter[] f = fm.getFiltersFromString(this.getConfiguration().getProperty(CFG_FILTER, ""));
String activeFilter = this.getFilterManager().getFiltersToLabelText(f, 45);
// get all defined Filters from configuration
List l = new ArrayList();
l.add(new IFilter[0]);
final IFilterManager jfm = getFilterManager();
Properties c = this.getConfiguration();
Iterator iter = c.keySet().iterator();
String key = null;
while (iter.hasNext()) {
key = (String) iter.next();
if (key.startsWith("filter_")) {
String filter = c.getProperty(key);
l.add(jfm.getFiltersFromString(filter));
}
}
// 2009/01/10: added sorting of filters
Collections.sort(l, new Comparator() {
public int compare(Object o1, Object o2) {
if (o1 instanceof IFilter[] && o2 instanceof IFilter[]) {
return jfm.getFiltersToLabelText((IFilter[]) o1, 45).compareToIgnoreCase(jfm.getFiltersToLabelText((IFilter[]) o2, 45));
}
return 0;
}
});
String[] filters = new String[l.size()];
int select = -1;
String filterAlias = null;
for (int i = 0; i < l.size(); i++) {
filterAlias = jfm.getFiltersToLabelText((IFilter[]) l.get(i), 45);
if (filterAlias.equalsIgnoreCase(activeFilter)) {
select = i;
}
filters[i] = filterAlias;
this.currentView.setData(filterAlias, (IFilter[]) l.get(i));
}
this.currentView.setItems(filters);
if (select == -1) {
getApplication().getConfiguration().setProperty(CFG_FILTER, jfm.getFiltersToString((IFilter[]) l.get(0)));
getApplication().storeConfiguration();
select = 0;
}
this.currentView.select(select);
this.currentView.setVisibleItemCount((this.currentView.getItemCount() > 16 ? 16 : this.currentView.getItemCount()));
this.currentView.pack();
this.currentView.getParent().pack();
}
// update menu bar
Menu m = this.getMenuBarManager().getMenu();
this.setMenuItemStatus(m);
new SWTExecuter(false, getID() + "-BuildTableThread") {
protected void execute() {
final ThreadStatus ts = new ThreadStatus();
class WorkerSWTExecuter extends SWTExecuter {
public WorkerSWTExecuter(boolean sync, String name) {
super(sync, name);
}
public void execute() {
try {
Cursor c = new Cursor(((TreeViewer) viewer).getTree().getDisplay(), SWT.CURSOR_WAIT);
Tree tree = ((TreeViewer) viewer).getTree();
AbstractMenuBuilder mb = getMenuBuilder();
if (mb != null)
tree.setMenu(mb.createPopupMenu(tree));
tree.getShell().setCursor(c);
long start = System.currentTimeMillis();
viewer.setInput(null);
viewer.setInput(m_controller);
// added: 2007/03/17: avoid dead lock in journal...
ts.setFinished(true);
tree.setFocus();
tree.setLinesVisible(getConfiguration().getProperty(CFG_SHOW_GRID, "true").equalsIgnoreCase("true"));
TreeColumn[] columns = tree.getColumns();
for (int i = 0; i < columns.length; i++) {
columns[i].setImage(null);
}
int sortcolumn = getOrderColumn(Integer.parseInt(getConfiguration().getProperty(CFG_ORDER, "0")));
if (sortcolumn > -1 && sortcolumn < columns.length) {
tree.setSortColumn(columns[sortcolumn]);
if (getConfiguration().getProperty(CFG_DIRECTION, "false").equalsIgnoreCase("false")) {
tree.setSortDirection(SWT.DOWN);
} else {
tree.setSortDirection(SWT.UP);
}
}
IAction action = getColoringAction();
if (action != null)
action.run();
action = getHightlightAction();
if (action != null)
action.run();
// set new title text...
String title_ext = getTitleExtension();
if (title_ext == null || title_ext.length() == 0)
tree.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()));
else
tree.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()) + " - " + title_ext);
tree.getShell().setCursor(null);
c.dispose();
ts.setFinished(true);
if (lastMarkedTreeItem > -1 && tree.getItemCount() > 0) {
TreeItem item = tree.getItem(Math.min(lastMarkedTreeItem, tree.getItemCount() - 1));
if (item != null) {
tree.setSelection(item);
tree.showSelection();
}
}
checkAmountOfEntries(start, System.currentTimeMillis());
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
if (ts != null)
ts.setFinished(true);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "refresherror", e));
}
}
}
;
final WorkerSWTExecuter workerThread = new WorkerSWTExecuter(false, getID() + "-SetDataToTableThread");
if (getConfiguration().getProperty(AbstractTableApplication.CFG_SHOW_REFRESH_POPUP, "true").equalsIgnoreCase("true")) {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "refreshprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
Thread t = new Thread() {
public void run() {
// preload data
try {
m_controller.getElementArray();
} catch (Exception ex) {
m_logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
};
t.setName("JAM-" + getID() + "#Preloader-Thread-(non-deamon)");
t.start();
Object repository = m_controller.getRepository();
do {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
if (repository instanceof ITracker) {
String msg = getI18nManager().getString(getNamespace(), "tracking", "label", getLanguage());
int leftover = Math.max(0, (((ITracker) repository).getTotal() - ((ITracker) repository).getCurrent()));
msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(leftover));
progressMonitor.subTask(msg);
}
} while (t.isAlive());
workerThread.start();
while (!ts.isFinished()) {
try {
progressMonitor.worked(1);
Thread.sleep(100);
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
progressMonitor.done();
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
// ModalContext.run(r, true, pmd.getProgressMonitor(),
// DisplayManager.getDefaultDisplay());
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (InvocationTargetException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
} else {
workerThread.execute();
}
// refresh status line
String message = m_controller.countElements() + getI18nManager().getString(getNamespace(), "items", "label", getLanguage());
if (fm != null) {
IFilter[] f = fm.getFiltersFromString(getConfiguration().getProperty(CFG_FILTER, ""));
if (f != null && f.length > 0) {
message += getI18nManager().getString(getNamespace(), "items_filtered", "label", getLanguage());
}
getStatusLineManager().setMessage(message);
}
}
}.start();
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class AbstractTableApplication method updateViews.
public synchronized void updateViews(Object[] controllerdata, boolean reload) {
// refresh controll data
refreshController(reload);
if (controllerdata != null)
this.m_controller.generateElementArray(controllerdata);
final IFilterManager fm = this.getFilterManager();
if (fm != null && this.getConfiguration().getProperty(CFG_ENABLE_FILTER_VIEW, "true").equalsIgnoreCase("true")) {
IFilter[] f = fm.getFiltersFromString(this.getConfiguration().getProperty(CFG_FILTER, ""));
String activeFilter = this.getFilterLabel(fm, f);
// get all defined Filters from configuration
List l = new ArrayList();
l.add(new IFilter[0]);
IFilterManager jfm = getFilterManager();
Properties c = this.getConfiguration();
Iterator iter = c.keySet().iterator();
String key = null;
while (iter.hasNext()) {
key = (String) iter.next();
if (key.startsWith("filter_")) {
String filter = c.getProperty(key);
l.add(jfm.getFiltersFromString(filter));
}
}
// added 2015/04/03: added runtime filters
if (jfm.hasRuntimeFilters()) {
IFilter[][] rf = jfm.getRuntimeFilters();
if (rf != null && rf.length > 0) {
for (int i = 0; i < rf.length; i++) l.add(rf[i]);
}
}
// added 2015/04/01: sort filter list
Collections.sort(l, new Comparator() {
public int compare(Object f1, Object f2) {
if (f1 != null && f2 != null && f1 instanceof IFilter[] && f2 instanceof IFilter[]) {
return getFilterLabel(getFilterManager(), ((IFilter[]) f1)).toLowerCase().compareTo(getFilterLabel(getFilterManager(), ((IFilter[]) f2)).toLowerCase());
// if (((IFilter[])f1).length==((IFilter[])f2).length) {
// return (((IFilter[])f2)[0].toString().compareTo(((IFilter[])f1)[0].toString()));
// }
// if (((IFilter[])f1).length<((IFilter[])f2).length) return -1;
// return 1;
}
return 0;
}
});
String[] filters = new String[l.size()];
int select = -1;
String filterAlias = null;
for (int i = 0; i < l.size(); i++) {
// this.getFilterManager().getFiltersToLabelText((IFilter[]) l.get(i),45);
filterAlias = this.getFilterLabel(fm, (IFilter[]) l.get(i));
if (filterAlias.equalsIgnoreCase(activeFilter)) {
select = i;
}
filters[i] = filterAlias;
this.currentView.setData(filterAlias, (IFilter[]) l.get(i));
}
this.currentView.setItems(filters);
if (select == -1) {
getApplication().getConfiguration().setProperty(CFG_FILTER, fm.getFiltersToString((IFilter[]) l.get(0)));
getApplication().storeConfiguration();
select = 0;
}
this.currentView.select(select);
this.currentView.setVisibleItemCount((this.currentView.getItemCount() > 16 ? 16 : this.currentView.getItemCount()));
this.currentView.pack();
this.currentView.getParent().pack();
}
// update menu bar
if (this.getMenuBarManager() != null) {
Menu m = this.getMenuBarManager().getMenu();
this.setMenuItemStatus(m);
}
new SWTExecuter(false, getID() + "-BuildTableThread") {
protected void execute() {
final ThreadStatus ts = new ThreadStatus();
class WorkerSWTExecuter extends SWTExecuter {
public WorkerSWTExecuter(boolean sync, String name) {
super(sync, name);
}
public void execute() {
try {
Cursor c = new Cursor(((TableViewer) viewer).getTable().getDisplay(), SWT.CURSOR_WAIT);
Table table = ((TableViewer) viewer).getTable();
AbstractMenuBuilder mb = getMenuBuilder();
if (mb != null)
table.setMenu(mb.createPopupMenu(table));
table.getShell().setCursor(c);
long start = System.currentTimeMillis();
viewer.setInput(null);
viewer.setInput(m_controller);
// added: 2007/03/17: avoid dead lock in journal...
ts.setFinished(true);
table.setFocus();
table.setLinesVisible(getConfiguration().getProperty(CFG_SHOW_GRID, "true").equalsIgnoreCase("true"));
TableColumn[] columns = table.getColumns();
for (int i = 0; i < columns.length; i++) {
columns[i].setImage(null);
}
int sortcolumn = getOrderColumn(Integer.parseInt(getConfiguration().getProperty(CFG_ORDER, "0")));
if (sortcolumn > -1 && sortcolumn < columns.length) {
table.setSortColumn(columns[sortcolumn]);
if (getConfiguration().getProperty(CFG_DIRECTION, "false").equalsIgnoreCase("false")) {
table.setSortDirection(SWT.DOWN);
} else {
table.setSortDirection(SWT.UP);
}
}
// IAction action = getColoringAction();
// if (action!=null)
// action.run();
IAction action = getHightlightAction();
if (action != null)
action.run();
// set new title text...
String title_ext = getTitleExtension();
if (title_ext == null || title_ext.length() == 0)
table.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()));
else
table.getShell().setText(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()) + " - " + title_ext);
table.getShell().setCursor(null);
c.dispose();
ts.setFinished(true);
if (lastMarkedRow > -1) {
table.setSelection(Math.min(lastMarkedRow, table.getItemCount()));
}
checkAmountOfEntries(start, System.currentTimeMillis());
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
if (ts != null)
ts.setFinished(true);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "refresherror", e));
}
}
}
;
final WorkerSWTExecuter workerThread = new WorkerSWTExecuter(false, getID() + "-SetDataToTableThread");
if (getConfiguration().getProperty(AbstractTableApplication.CFG_SHOW_REFRESH_POPUP, "true").equalsIgnoreCase("true")) {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "refreshprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
Thread t = new Thread() {
public void run() {
// preload data
try {
m_controller.getElementArray();
} catch (Exception ex) {
m_logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
};
t.setName("JAM-" + getID() + "#Preloader-Thread-(non-deamon)");
t.start();
Object repository = m_controller.getRepository();
do {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
if (repository instanceof ITracker) {
String msg = getI18nManager().getString(getNamespace(), "tracking", "label", getLanguage());
int leftover = Math.max(0, (((ITracker) repository).getTotal() - ((ITracker) repository).getCurrent()));
msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(leftover));
progressMonitor.subTask(msg);
}
} while (t.isAlive());
workerThread.start();
while (!ts.isFinished()) {
try {
progressMonitor.worked(1);
Thread.sleep(100);
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
progressMonitor.done();
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
// ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (InvocationTargetException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
} else {
workerThread.execute();
}
// refresh status line
String message = m_controller.countElements() + getI18nManager().getString(getNamespace(), "items", "label", getLanguage());
if (fm != null) {
IFilter[] f = fm.getFiltersFromString(getConfiguration().getProperty(CFG_FILTER, ""));
if (f != null && f.length > 0 && getConfiguration().getProperty(CFG_ENABLE_FILTER_VIEW, "true").equalsIgnoreCase("true")) {
message += getI18nManager().getString(getNamespace(), "items_filtered", "label", getLanguage());
}
getStatusLineManager().setMessage(message);
}
}
}.start();
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class LastCalled method renderAsText.
public String renderAsText() {
if (this.m_o != null) {
if (this.m_o instanceof ICaller) {
this.m_o = new TreeItemCallerData(((ICaller) this.m_o).getAttributes(), ((ICaller) this.m_o).getPhoneNumber());
}
if (this.m_o instanceof ITreeItemCallerData) {
IPhonenumber pn = ((ITreeItemCallerData) m_o).getPhone();
List cms = PIMRuntime.getInstance().getCallManagerFactory().getTypedCallManagers(IReadCallRepository.class);
if (cms.size() > 0) {
ICallManager cm = null;
for (int i = 0, j = cms.size(); i < j; i++) {
cm = (ICallManager) cms.get(i);
if (cm.isActive() && cm.isSupported(IReadCallRepository.class)) {
IFilter[] filters = new IFilter[] { new PhonenumberFilter(pn), new ItemCountFilter(1) };
ICallList cl = ((IReadCallRepository) cm).getCalls(filters, 1, 0);
cl.sort(0, false);
if (cl.size() > 0) {
ICall c = cl.get(0);
return getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLTIME, c.getDate());
}
}
}
}
}
}
return "";
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class GetCallListCount method getAllowedMsnFilter.
private IFilter[] getAllowedMsnFilter(IHttpRequest req) throws HandlerException {
try {
boolean allowedForAllMsns = (SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName()) == null && SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress()) == null);
if (!allowedForAllMsns) {
String[] allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName());
if (allowedMSNs == null)
allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress());
if (allowedMSNs != null) {
IFilter[] allowedMsnFilter = new IFilter[allowedMSNs.length];
IMsn msn = null;
for (int i = 0; i < allowedMSNs.length; i++) {
msn = getRuntime().getMsnManager().createMsn(allowedMSNs[i]);
allowedMsnFilter[i] = new MsnFilter(msn);
m_logger.info("Adding allowed MSN filter for client: " + allowedMsnFilter[i].toString());
}
return allowedMsnFilter;
}
}
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new HandlerException(e.getMessage(), 500);
}
return new IFilter[0];
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class GetCallList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallManager mgr = null;
String manager = null;
boolean isCompression = false;
try {
manager = req.getParameter(GetCallList.PARAMETER_CALLMANAGER);
isCompression = (req.getParameter(GetCallList.PARAMETER_COMPRESSION) != null ? req.getParameter(GetCallList.PARAMETER_COMPRESSION).equalsIgnoreCase("true") : false);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallManagerFactory().getDefaultCallManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallRepository.class)) {
throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
}
ICallList l = this.getRuntime().getCallFactory().createCallList();
String filter = null;
try {
filter = req.getParameter(GetCallList.PARAMETER_FILTER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
String s = null;
ISearchTerm[] searchterms = null;
try {
s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (s != null && s.length() > 0) {
searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
}
if (filter == null || filter.length() == 0) {
this.m_logger.info("Filter parameter &filter= was not set.");
if (mgr.isSupported(ISearchableCallRepository.class)) {
l = ((ISearchableCallRepository) mgr).getCalls(getAllowedMsnFilter(req), -1, -1, searchterms);
} else
l = ((IReadCallRepository) mgr).getCalls(getAllowedMsnFilter(req));
} else {
IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
f = mergeFilters(f, getAllowedMsnFilter(req));
if (mgr.isSupported(ISearchableCallRepository.class)) {
l = ((ISearchableCallRepository) mgr).getCalls(f, -1, -1, searchterms);
} else
l = ((IReadCallRepository) mgr).getCalls(f);
}
try {
String xml = XMLSerializer.toXML(l, false);
if (isCompression && xml.length() > 1024) {
this.m_logger.info("Compressing requested data.");
this.m_logger.info("Uncompressed data size [bytes] : " + xml.length());
xml = CompressBase64.compressBase64Encode(xml);
this.m_logger.info("Compressed data size [bytes] : " + xml.length());
resp.setParameter("Content-Type", "application/janrufmonitor-compressed");
resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "true");
} else {
resp.setParameter("Content-Type", "text/xml");
resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "false");
}
resp.setParameter("Content-Length", Long.toString(xml.length()));
OutputStream ps = resp.getContentStreamForWrite();
ps.write(xml.getBytes());
ps.flush();
ps.close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations