use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class IdentifyAction method run.
public synchronized void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null && v instanceof Viewer) {
final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
if (selection.getFirstElement() instanceof ICaller) {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "identifyprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
final ICaller caller = (ICaller) selection.getFirstElement();
List phones = new ArrayList();
if (caller instanceof IMultiPhoneCaller) {
phones.addAll(((IMultiPhoneCaller) caller).getPhonenumbers());
} else {
phones.add(caller.getPhoneNumber());
}
String ignoreCM = "";
IAttribute att = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
if (att != null) {
ignoreCM = att.getValue();
}
List activeCMs = getAllActiveCallerManagers(getRuntime(), ignoreCM);
ICaller identifiedCaller = null;
// identification only makes sence if there are active CMs or if there are numbers
if (activeCMs.size() > 0 && phones.size() > 0) {
IPhonenumber pn = null;
for (int i = 0; i < phones.size(); i++) {
pn = (IPhonenumber) phones.get(i);
identifiedCaller = Identifier.identify(getRuntime(), pn, activeCMs);
if (identifiedCaller != null)
break;
}
}
progressMonitor.done();
if (identifiedCaller == null) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "failedidentify", "label", getLanguage()), IProgressMonitor.UNKNOWN);
PropagationFactory.getInstance().fire(new Message(Message.INFO, getNamespace(), "failedidentify", new Exception("Caller with number " + caller.getPhoneNumber() + " not identified...")));
return;
}
// remove repository flag and set all numbers
if (!(identifiedCaller instanceof IMultiPhoneCaller)) {
identifiedCaller = getRuntime().getCallerFactory().toMultiPhoneCaller(identifiedCaller);
}
((IMultiPhoneCaller) identifiedCaller).setPhonenumbers(phones);
((IMultiPhoneCaller) identifiedCaller).setPhoneNumber((IPhonenumber) phones.get(0));
IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
m.addAll(caller.getAttributes());
m.addAll(identifiedCaller.getAttributes());
m.remove(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
identifiedCaller.setAttributes(m);
final ICaller theIdentifiedCaller = identifiedCaller;
new SWTExecuter() {
protected void execute() {
if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "identify", "label", getLanguage()), getI18nManager().getString(getNamespace(), "identify", "description", getLanguage()))) {
ICaller newCaller = openCallerWizard(theIdentifiedCaller);
if (newCaller != null) {
ICallerList list = getRuntime().getCallerFactory().createCallerList(1);
list.add(caller);
m_app.getController().deleteElements(list);
list.clear();
list.add(newCaller);
m_app.getController().addElements(list);
m_app.updateViews(true);
}
}
}
}.start();
}
};
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);
}
}
}
}
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class SingleVcfExportAction method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null && v instanceof Viewer) {
final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Iterator it = selection.iterator();
final ICallerList list = this.getRuntime().getCallerFactory().createCallerList(selection.size());
Object o = null;
while (it.hasNext()) {
o = it.next();
if (o instanceof ICaller) {
list.add((ICaller) o);
}
}
try {
FileDialog dialog = new FileDialog(new Shell(DisplayManager.getDefaultDisplay()), SWT.SAVE);
dialog.setText(this.getI18nManager().getString(this.getNamespace(), "title", "label", this.getLanguage()));
if (list.size() == 1) {
dialog.setFileName(((ICaller) list.get(0)).getName().getFirstname() + " " + ((ICaller) list.get(0)).getName().getLastname());
}
if (ImExportFactory.getInstance().getExporter("VcfFileCallerExporter") == null)
return;
List ids = new ArrayList();
ids.add("VcfFileCallerExporter");
String[] filternames = new String[ids.size()];
String[] extensions = new String[ids.size()];
IImExporter ie = null;
for (int i = 0; i < ids.size(); i++) {
ie = ImExportFactory.getInstance().getExporter((String) ids.get(i));
filternames[i] = ie.getFilterName();
extensions[i] = ie.getExtension();
}
dialog.setFilterNames(filternames);
dialog.setFilterExtensions(extensions);
String filter = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(getNamespace(), "lastopeneddir");
if (filter == null || filter.length() == 0 || !new File(filter).exists())
filter = PathResolver.getInstance(getRuntime()).getDataDirectory();
dialog.setFilterPath(filter);
final String filename = dialog.open();
if (filename == null)
return;
filter = new File(filename).getParentFile().getAbsolutePath();
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), "lastopeneddir", filter);
String ext = "";
for (int i = 0; i < ids.size(); i++) {
final IImExporter exp = ImExportFactory.getInstance().getExporter((String) ids.get(i));
ext = exp.getExtension().substring(1);
if (filename.toLowerCase().endsWith(ext) && exp.getMode() == IImExporter.CALLER_MODE) {
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "exportprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
((ICallerExporter) exp).setCallerList(list);
exp.setFilename(filename);
if (((ICallerExporter) exp).doExport()) {
progressMonitor.done();
PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "success", "description", getLanguage()))), "Tray");
} else {
progressMonitor.done();
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("Export of contacts failed.");
}
}.start();
}
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
} catch (InterruptedException e) {
throw e;
} catch (InvocationTargetException e) {
throw e;
}
// m_app.updateViews(false);
}
}
} catch (Exception ex) {
this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "error", ex));
}
}
}
}
use of de.janrufmonitor.framework.ICallerList 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.framework.ICallerList in project janrufmonitor by tbrandt77.
the class EditorController method updateElement.
public synchronized void updateElement(Object element) {
if (element != null && element instanceof ICallerList) {
ICallerManager mgr = this._getRepository();
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
for (int i = 0, j = ((ICallerList) element).size(); i < j; i++) {
((IWriteCallerRepository) mgr).updateCaller(((ICallerList) element).get(i));
}
}
}
}
if (element != null && element instanceof ICaller) {
List managers = this.getActiveCallerManagers();
ICallerManager mgr = null;
IAttribute att = ((ICaller) element).getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
for (int i = 0; i < managers.size(); i++) {
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
if (att == null || att.getValue().equalsIgnoreCase(mgr.getManagerID()))
((IWriteCallerRepository) mgr).updateCaller((ICaller) element);
}
}
}
}
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class CombineAction method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Iterator i = selection.iterator();
ICallerList list = getRuntime().getCallerFactory().createCallerList();
ICallerList olist = getRuntime().getCallerFactory().createCallerList();
Object o = null;
while (i.hasNext()) {
o = i.next();
olist.add((ICaller) o);
if (o instanceof IMultiPhoneCaller) {
list.add((IMultiPhoneCaller) o);
} else if (o instanceof ICaller) {
list.add(getRuntime().getCallerFactory().toMultiPhoneCaller((ICaller) o));
}
}
if (list.size() < 2)
return;
Display display = DisplayManager.getDefaultDisplay();
Shell shell = new Shell(display);
WizardDialog.setDefaultImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_PIM_ICON));
CallerCombineWizard callerWiz = new CallerCombineWizard(list);
WizardDialog dlg = new WizardDialog(shell, callerWiz);
dlg.open();
if (dlg.getReturnCode() == WizardDialog.OK) {
IMultiPhoneCaller c = callerWiz.getResult();
if (c != null) {
// remove merged contact from olist
ICaller ca, rmc = null;
for (int j = olist.size() - 1; j >= 0; j--) {
ca = olist.get(j);
if (ca.getUUID().equalsIgnoreCase(c.getUUID())) {
rmc = ca;
m_logger.info("Merged user detected: " + rmc);
}
}
if (rmc != null)
olist.remove(rmc);
this.m_app.getController().deleteElements(olist);
this.m_app.getController().updateElement(c);
this.m_app.updateViews(true);
}
}
}
}
}
Aggregations