use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.
the class AbstractPhonesPage method createControl.
public void createControl(Composite parent) {
setTitle(this.m_i18n.getString(getNamespace(), "title", "label", this.m_language));
setDescription(this.m_i18n.getString(getNamespace(), "description", "label", this.m_language));
Composite c = new Composite(parent, SWT.NONE);
c.setLayout(new GridLayout(1, false));
c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
all = new Button(c, SWT.CHECK);
all.setText(this.m_i18n.getString(this.getNamespace(), "*", "label", this.m_language));
all.setSelection((this.getCallers().size() == 0 ? true : false));
Label ln = new Label(c, SWT.LEFT);
Composite select = new Composite(c, SWT.NONE);
select.setLayout(new GridLayout(3, false));
select.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
ln = new Label(select, SWT.LEFT);
ln.setText(this.m_i18n.getString(this.getNamespace(), "allphones", "label", this.m_language));
ln = new Label(select, SWT.LEFT);
ln = new Label(select, SWT.LEFT);
ln.setText(this.m_i18n.getString(this.getNamespace(), "selectedphones", "label", this.m_language));
final CheckboxTableViewer call = CheckboxTableViewer.newCheckList(select, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL);
call.setLabelProvider(new CallerLabelProvider());
call.setContentProvider(new CallerContentProvider());
call.setInput(null);
ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "refreshprogress", "label", m_language), IProgressMonitor.UNKNOWN);
final List callers = new ArrayList();
Thread t = new Thread() {
public void run() {
// preload data
try {
callers.addAll(getAllCallers());
} catch (Exception ex) {
m_logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
};
t.setName("JAM-ContactsRead-Thread-(non-deamon)");
t.start();
int lastamount = -1;
do {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
m_currentCallerManager = CallerReaderFactory.getInstance().getCurrent();
if (m_currentCallerManager != null && m_currentCallerManager instanceof ITracker) {
int leftover = Math.max(0, (((ITracker) m_currentCallerManager).getTotal() - ((ITracker) m_currentCallerManager).getCurrent()));
if (lastamount == leftover) {
String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "working", "label", m_language);
progressMonitor.subTask(msg);
} else {
String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "tracking", "label", m_language);
msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(leftover));
if (m_currentCallerManager instanceof IConfigurable) {
msg = StringUtils.replaceString(msg, "{%2}", m_i18n.getString(((IConfigurable) m_currentCallerManager).getNamespace(), "title", "label", m_language));
} else {
msg = StringUtils.replaceString(msg, "{%2}", m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "nocallermanager", "label", m_language));
}
progressMonitor.subTask(msg);
}
lastamount = leftover;
} else {
String msg = m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "notracking", "label", m_language);
if (m_currentCallerManager instanceof IConfigurable) {
msg = StringUtils.replaceString(msg, "{%1}", m_i18n.getString(((IConfigurable) m_currentCallerManager).getNamespace(), "title", "label", m_language));
} else {
msg = StringUtils.replaceString(msg, "{%1}", m_i18n.getString("ui.jface.wizards.pages.AbstractPhonesPage", "nocallermanager", "label", m_language));
}
progressMonitor.subTask(msg);
}
} while (t.isAlive());
SWTExecuter tt = new SWTExecuter("ContactsRefresh") {
protected void execute() {
call.setInput(callers);
}
};
tt.start();
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);
}
GridData gd = new GridData(200, 200);
call.getTable().setLayoutData(gd);
Composite btns = new Composite(select, SWT.NONE);
btns.setLayout(new GridLayout(1, false));
btns.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Button add = new Button(btns, SWT.PUSH);
add.setText(this.m_i18n.getString(this.getNamespace(), "add", "label", this.m_language));
final Button remove = new Button(btns, SWT.PUSH);
remove.setText(this.m_i18n.getString(this.getNamespace(), "remove", "label", this.m_language));
final CheckboxTableViewer cselect = CheckboxTableViewer.newCheckList(select, SWT.CHECK | SWT.BORDER);
cselect.setLabelProvider(new CallerLabelProvider());
cselect.setContentProvider(new CallerContentProvider());
List selected = this.getCallers();
cselect.setInput(selected);
gd = new GridData(200, 200);
cselect.getTable().setLayoutData(gd);
all.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
add.setEnabled(!all.getSelection());
remove.setEnabled(!all.getSelection());
call.setAllGrayed(all.getSelection());
cselect.setAllGrayed(all.getSelection());
}
});
add.setEnabled(!all.getSelection());
remove.setEnabled(!all.getSelection());
call.setAllGrayed(all.getSelection());
cselect.setAllGrayed(all.getSelection());
add.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Object[] checked = call.getCheckedElements();
if (checked != null && checked.length > 0) {
for (int i = 0; i < checked.length; i++) {
if (!m_selectedCallers.contains(checked[i]))
m_selectedCallers.add(checked[i]);
}
cselect.setInput(m_selectedCallers);
}
}
});
remove.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Object[] checked = cselect.getCheckedElements();
if (checked != null && checked.length > 0) {
for (int i = 0; i < checked.length; i++) {
if (m_selectedCallers.contains(checked[i]))
m_selectedCallers.remove(checked[i]);
}
cselect.setInput(m_selectedCallers);
}
}
});
setPageComplete(true);
setControl(c);
}
use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.
the class TamMessagePlay method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Object o = selection.getFirstElement();
if (o instanceof ICall) {
if (((ICall) o).getAttributes().contains("fritzbox.tamurl")) {
File message_file = null;
String url = ((ICall) o).getAttributes().get("fritzbox.tamurl").getValue();
File tamMessageDir = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getDataDirectory() + File.separator + "fritzbox-messages");
tamMessageDir.mkdirs();
if (tamMessageDir.exists() && tamMessageDir.isDirectory()) {
message_file = new File(tamMessageDir, ((ICall) o).getUUID() + ".wav");
if (!message_file.exists()) {
FirmwareManager fwm = FirmwareManager.getInstance();
try {
if (!fwm.isLoggedIn())
fwm.login();
String data = fwm.getTamMessage(url);
if (data == null)
return;
ByteArrayInputStream bin = new ByteArrayInputStream(data.getBytes());
Base64Decoder b64 = new Base64Decoder(bin);
FileOutputStream fos = new FileOutputStream(message_file);
Stream.copy(b64, fos);
fos.flush();
fos.close();
} catch (IOException e) {
this.m_logger.warning(e.toString());
} catch (FritzBoxLoginException e) {
this.m_logger.warning(e.toString());
}
}
}
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(message_file);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
} catch (IOException e) {
this.m_logger.severe(e.getMessage());
} catch (LineUnavailableException e) {
this.m_logger.severe(e.getMessage());
} catch (UnsupportedAudioFileException e) {
this.m_logger.severe(e.getMessage());
}
} else {
new SWTExecuter() {
protected void execute() {
int style = SWT.APPLICATION_MODAL | SWT.OK;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
messageBox.setMessage(getI18nManager().getString(getNamespace(), "notam", "label", getLanguage()));
messageBox.open();
}
}.start();
return;
}
}
}
}
}
use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.
the class DefaultCallDialogService method receivedValidRule.
public void receivedValidRule(final ICall aCall) {
ICaller theCaller = aCall.getCaller();
if (theCaller != null) {
this.m_logger.info("Opening new dialog instance...");
final long ms = System.currentTimeMillis();
this.m_logger.fine("Time measure in ms (init): " + (System.currentTimeMillis() - ms));
new SWTExecuter(true, this.getID()) {
protected void execute() {
if (m_configuration.getProperty(CFG_BALLOON, "false").equalsIgnoreCase("false")) {
m_logger.fine("Time measure in ms (SWTExecuter): " + (System.currentTimeMillis() - ms));
Dialog j = new Dialog(m_configuration, aCall);
m_logger.fine("Time measure in ms (SWTExecuter.open() - before): " + (System.currentTimeMillis() - ms));
j.open();
m_logger.fine("Time measure in ms (SWTExecuter.open() - after): " + (System.currentTimeMillis() - ms));
j = null;
} else {
m_logger.fine("Time measure in ms (SWTExecuter): " + (System.currentTimeMillis() - ms));
ExtendedBalloonDialog j = new ExtendedBalloonDialog(m_configuration, aCall);
try {
Thread.sleep(getDelay());
} catch (InterruptedException e) {
}
j.createDialog();
m_logger.fine("Time measure in ms (SWTExecuter.open() - before): " + (System.currentTimeMillis() - ms));
j.open();
m_logger.fine("Time measure in ms (SWTExecuter.open() - after): " + (System.currentTimeMillis() - ms));
j = null;
}
}
}.start();
this.m_logger.fine("Time measure in ms (end): " + (System.currentTimeMillis() - ms));
} else {
this.m_logger.warning("Dialog not opened due to invalid caller data.");
}
}
use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.
the class TrayIcon method setIconStateMonitorListener.
public void setIconStateMonitorListener() {
if (getRuntime().getMonitorListener().getDefaultMonitor() == null)
return;
final boolean started = getRuntime().getMonitorListener().getDefaultMonitor().isStarted();
new SWTExecuter() {
protected void execute() {
if (trayItem == null || trayItem.isDisposed())
return;
if (OSUtils.isWindows())
trayItem.setVisible(false);
trayItem.setImage(SWTImageManager.getInstance(getRuntime()).get((started ? IJAMConst.IMAGE_KEY_PIM_ICON : IJAMConst.IMAGE_KEY_PIMX_ICON)));
if (OSUtils.isWindows())
trayItem.setVisible(true);
}
}.start();
setItemChecked("Activator", started);
}
use of de.janrufmonitor.ui.swt.SWTExecuter in project janrufmonitor by tbrandt77.
the class Dialog method createContents.
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
Group g = new Group(composite, SWT.SHADOW_ETCHED_IN);
g.setLayout(new GridLayout(2, false));
Label date = new Label(g, SWT.NONE);
date.setText(this.getI18nManager().getString(this.getNamespace(), "date_label", "label", this.getLanguage()) + this.getParsedDate());
Font initialFont = date.getFont();
FontData[] fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(this.getFontSize() - 3);
}
Font newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
date.setFont(newFont);
boolean hasCallerImage = this.hasCallerImage();
Label image = new Label(g, SWT.BORDER | SWT.RIGHT);
GridData gd = new GridData();
gd.verticalSpan = 6;
image.setVisible(false);
if (hasCallerImage) {
gd.widthHint = 92;
gd.heightHint = 110;
gd.horizontalIndent = 10;
image.setVisible(true);
image.setImage(this.getCallerImage());
}
image.setLayoutData(gd);
Label msn = new Label(g, SWT.NONE);
msn.setText(this.getI18nManager().getString(this.getNamespace(), "msn_label", "label", this.getLanguage()) + this.getParsedMsn());
initialFont = msn.getFont();
fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(this.getFontSize() - 3);
fontData[i].setStyle(SWT.BOLD);
}
newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
msn.setFont(newFont);
Label callerLabel = new Label(g, SWT.NONE);
callerLabel.setText(this.getI18nManager().getString(this.getNamespace(), "caller_label", "label", this.getLanguage()));
initialFont = callerLabel.getFont();
fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(this.getFontSize() - 3);
}
newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
callerLabel.setFont(newFont);
caller = new Label(g, SWT.WRAP);
caller.setText(this.getParsedCaller());
caller.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
initialFont = caller.getFont();
fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(this.getFontSize());
fontData[i].setStyle(SWT.BOLD);
}
newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
caller.setFont(newFont);
caller.pack();
this.checkCallerLength(caller);
caller.pack();
// added 2008/04/08: add provider image if present
Composite numberbar = new Composite(g, SWT.NONE);
ITableCellRenderer tr = RendererRegistry.getInstance().getRenderer("ProviderLogo".toLowerCase());
Image img = null;
Label l = null;
if (tr != null && this.m_call != null && !isCliredCaller()) {
tr.updateData(this.m_call);
img = tr.renderAsImage();
}
numberbar.setLayout(new GridLayout((img != null ? 2 : 1), false));
if (img != null) {
l = new Label(numberbar, SWT.LEFT);
l.setImage(new Image(DisplayManager.getDefaultDisplay(), img.getImageData().scaledTo(32, 32)));
}
Label number = new Label(numberbar, SWT.NONE);
number.setText(this.getParsedNumber());
number.setForeground(new Color(DisplayManager.getDefaultDisplay(), this.getColor()));
initialFont = number.getFont();
fontData = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++) {
fontData[i].setHeight(this.getFontSize() - 3);
fontData[i].setStyle(SWT.BOLD);
}
newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
number.setFont(newFont);
new Label(g, SWT.NONE).setText(this.getParsedCip());
// check for plugins
List plugins = this.getPlugins(this.getConfiguration().getProperty("pluginlist", ""));
Composite buttonbar = new Composite(composite, SWT.NONE);
buttonbar.setLayout(new GridLayout(Math.max(4, (plugins.size() + 2)), false));
// check for active reject service
IService rejectService = this.getRuntime().getServiceFactory().getService("Reject");
if (rejectService != null && rejectService.isEnabled()) {
reject = new Button(buttonbar, SWT.PUSH);
reject.setText(this.getI18nManager().getString(this.getNamespace(), "reject", "label", this.getLanguage()));
reject.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Button) {
reject.setEnabled(false);
IEventBroker eventBroker = getRuntime().getEventBroker();
if (getCall() != null)
getCall().setAttribute(getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
eventBroker.send(Dialog.this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLREJECTED, getCall()));
}
}
});
}
// dialog close manually
if (this.getShowTime() == -2) {
Button close = new Button(buttonbar, SWT.PUSH);
close.setText(this.getI18nManager().getString(this.getNamespace(), "close", "label", this.getLanguage()));
close.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Button) {
close();
}
}
});
}
// name assign is active
if (this.isAssignement() && !this.isCliredCaller()) {
Button assign = new Button(buttonbar, SWT.PUSH);
assign.setText(this.getI18nManager().getString(this.getNamespace(), "assign", "label", this.getLanguage()));
assign.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Button) {
Thread thread = new Thread() {
public void run() {
DisplayManager.getDefaultDisplay().asyncExec(new NameAssignDialog(getCaller()));
}
};
thread.setName(getID());
thread.start();
}
}
});
}
// add plugins
String classString = null;
for (int i = 0, j = plugins.size(); i < j; i++) {
classString = this.getConfiguration().getProperty((String) plugins.get(i));
if (classString != null && classString.trim().length() > 0) {
try {
Class classObject = Thread.currentThread().getContextClassLoader().loadClass(classString);
final IDialogPlugin plugin = (IDialogPlugin) classObject.newInstance();
plugin.setDialog(this);
plugin.setID((String) plugins.get(i));
if (plugin.isEnabled()) {
Button button = new Button(buttonbar, SWT.PUSH);
button.setText(plugin.getLabel());
button.pack();
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Button) {
plugin.run();
}
}
});
}
} catch (ClassNotFoundException e) {
this.m_logger.warning("Class not found: " + classString);
} catch (InstantiationException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IllegalAccessException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
if (this.getShowTime() > 0) {
Timer aTimer = new Timer();
aTimer.schedule(new TimerTask() {
public void run() {
new SWTExecuter(getID()) {
protected void execute() {
close();
}
}.start();
}
}, (long) ((this.getShowDuration() + 1) * 1000));
}
gd = new GridData();
if (!hasCallerImage) {
gd.widthHint = Math.max(350, this.caller.getBounds().width + 10);
}
g.setLayoutData(gd);
parent.getShell().pack();
return composite;
}
Aggregations