use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class OldDatFileCallImporter method migrateCallFromString.
private ICall migrateCallFromString(String scall, String datePattern) {
if (scall != null && scall.trim().length() == 0)
return null;
try {
StringTokenizer st = new StringTokenizer(scall, "%$");
if (st.countTokens() < 5) {
this.m_logger.warning("Invalid entry found: entry was dropped for migration.");
return null;
}
String state = st.nextToken().trim();
String msn = st.nextToken().trim();
String caller = st.nextToken().trim();
String cip = st.nextToken().trim();
String date = st.nextToken().trim();
// parse MSN
IMsn parsedMSN = this.parseMsn(msn);
ICip parsedCIP = this.parseCip(cip);
IAttribute att = this.parseState(state);
IPhonenumber phone = this.parsePhone(caller);
IName name = this.parseName(caller);
ICaller parsedCaller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phone);
Date parsedDate = this.parseDate(date, datePattern);
ICall aCall = PIMRuntime.getInstance().getCallFactory().createCall(parsedCaller, parsedMSN, parsedCIP, parsedDate);
if (!att.getName().equalsIgnoreCase("")) {
aCall.setAttribute(att);
}
this.m_logger.info(aCall.toString());
return aCall;
} catch (NoSuchElementException ex) {
this.m_logger.warning("FormatException: migration failed due to incompatible format information.");
} catch (NullPointerException ex) {
this.m_logger.warning("Invalid entry found: entry was dropped for migration.");
}
return null;
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class OldDatFileCallerImporter method migrateCallerFromString.
private ICaller migrateCallerFromString(String scaller) {
if (scaller != null && scaller.trim().length() == 0)
return null;
StringTokenizer st = new StringTokenizer(scaller, ";");
String number = st.nextToken().trim();
String caller = st.nextToken().trim();
String reject = "0";
if (st.hasMoreTokens())
reject = st.nextToken().trim();
IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(number.substring(1));
try {
ICaller migCaller = null;
ICallerManager def = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
if (def != null && def.isActive() && def.isSupported(IIdentifyCallerRepository.class)) {
migCaller = ((IIdentifyCallerRepository) def).getCaller(pn);
} else
throw new CallerNotFoundException();
StringTokenizer ctoken = new StringTokenizer(caller, " ");
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
if (ctoken.hasMoreTokens()) {
name.setFirstname(ctoken.nextToken());
}
if (ctoken.hasMoreTokens()) {
name.setLastname(ctoken.nextToken());
}
if (ctoken.hasMoreTokens()) {
name.setAdditional(ctoken.nextToken());
}
while (ctoken.hasMoreTokens()) {
name.setAdditional(name.getAdditional() + " " + ctoken.nextToken());
}
migCaller.setName(name);
if (reject.equalsIgnoreCase("1")) {
IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_YES);
migCaller.setAttribute(att);
}
if (reject.equalsIgnoreCase("0")) {
IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_NO);
migCaller.setAttribute(att);
}
LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).info(migCaller.toString());
return migCaller;
} catch (CallerNotFoundException e) {
LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).warning(e.getMessage());
}
return null;
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class Duration method getDuration.
private String getDuration(ICall call) {
IAttribute ring = call.getAttribute("fritzbox.duration");
if (ring != null) {
try {
int duration = Integer.parseInt(ring.getValue()) / 60;
StringBuffer sb = new StringBuffer(64);
if ((duration / 60) > 0) {
sb.append((duration / 60));
sb.append(" h ");
}
sb.append((duration % 60));
sb.append(" min ");
return sb.toString();
} catch (Exception e) {
}
}
return "";
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class PDFCreator method createPdf.
public void createPdf() {
Document document = new Document(PageSize.A4);
document.addCreationDate();
document.addCreator("jAnrufmonitor");
try {
PdfWriter.getInstance(document, new FileOutputStream(this.m_file));
document.open();
document.add(new Paragraph(this.getI18nManager().getString(getNamespce(), "pdftitle", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 16f, Font.BOLD | Font.UNDERLINE)));
document.add(new Paragraph(" "));
String msg = "";
ITableCellRenderer tcr = RendererRegistry.getInstance().getRenderer("name");
if (tcr != null) {
tcr.updateData(m_cc.getCaller());
msg += tcr.renderAsText();
}
tcr = RendererRegistry.getInstance().getRenderer("number");
if (tcr != null) {
tcr.updateData(m_cc.getCaller());
msg += "\n" + tcr.renderAsText() + "\n";
}
document.add(new Paragraph(msg));
document.add(new Paragraph(" "));
List comments = m_cc.getComments();
Collections.sort(comments, new CommentComparator());
IComment c = null;
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100f);
PdfPCell cp = null;
Paragraph pp = null;
Color iterateColor1 = new Color(0xDD, 0xDD, 0xDD);
Color iterateColor2 = new Color(0xFF, 0xFF, 0xFF);
for (int i = 0; i < comments.size(); i++) {
cp = new PdfPCell();
cp.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
pp = new Paragraph();
Paragraph p = new Paragraph();
c = (IComment) comments.get(i);
IAttribute att = c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_SUBJECT);
if (att != null && att.getValue().length() > 0) {
p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfsubject", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 14f, Font.BOLD)));
p.add(new Chunk(att.getValue(), FontFactory.getFont(FontFactory.HELVETICA, 14f, Font.BOLD)));
pp.add(p);
p = new Paragraph();
}
p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfdate", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD)));
p.add(new Chunk(getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLTIME, c.getDate())));
pp.add(p);
p = new Paragraph();
p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfstatus", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD)));
p.add(new Chunk(c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_STATUS).getValue()));
pp.add(p);
att = c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_FOLLOWUP);
if (att != null && att.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_YES)) {
p = new Paragraph();
Chunk cu = new Chunk(this.getI18nManager().getString(getNamespce(), "pdffollowup", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD));
cu.setBackground(new Color(0xFF, 0xFF, 0x00));
p.add(cu);
pp.add(p);
}
pp.add(new Paragraph(" "));
p = new Paragraph(c.getText());
pp.add(p);
cp.addElement(pp);
table.addCell(cp);
}
document.add(table);
} catch (DocumentException de) {
this.m_logger.severe(de.getMessage());
} catch (IOException ioe) {
this.m_logger.severe(ioe.getMessage());
} finally {
document.close();
}
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class MultiPhoneCallerPage method createControl.
public void createControl(Composite parent) {
Composite c = new Composite(parent, SWT.NONE);
c.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 40 : 0);
gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
c.setLayoutData(gd);
// CALLER DATA
Group callerGroup = new Group(c, SWT.SHADOW_ETCHED_IN);
callerGroup.setText(this.m_i18n.getString(getNamespace(), "callergroup", "label", this.m_language));
callerGroup.setLayout(new GridLayout(2, false));
callerGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME), 210, 0, this.m_callerReadonly);
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME), 210, 0, this.m_callerReadonly);
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL), 0, 2, this.m_callerReadonly);
this.renderAsText(callerGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL), 0, 2, this.m_callerReadonly);
// ADDRESS AREA
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
Group addressGroup = new Group(callerGroup, SWT.SHADOW_ETCHED_IN);
addressGroup.setText(this.m_i18n.getString(getNamespace(), "addressgroup", "label", this.m_language));
addressGroup.setLayout(new GridLayout(3, false));
addressGroup.setLayoutData(gd);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET), 370, 2, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO), 0, 0, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE), 75, 0, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY), 345, 2, this.m_callerReadonly);
this.renderAsText(addressGroup, getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY), 0, 3, this.m_callerReadonly);
Composite t = new Composite(c, SWT.NONE);
t.setLayout(new GridLayout(2, false));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.verticalSpan = 2;
gd.verticalIndent = 10;
gd.verticalAlignment = GridData.VERTICAL_ALIGN_END;
t.setLayoutData(gd);
// IMAGE
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
if (OSUtils.isMacOSX()) {
gd.heightHint = 110;
final Label image = new Label(t, SWT.NONE);
image.setLayoutData(gd);
image.setImage(this.getCallerImage());
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
} else {
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
}
new Label(t, SWT.NONE);
image.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent arg0) {
if (!m_callerReadonly) {
FileDialog fde = new FileDialog(getShell(), SWT.OPEN);
fde.setFilterExtensions(new String[] { "*.jpg", "*.jpeg", "*.gif", "*.png" });
fde.setText(m_i18n.getString(getNamespace(), "select", "label", m_language));
fde.setFilterPath(PathResolver.getInstance(getRuntime()).resolve(getAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)));
String imagePath = fde.open();
if (imagePath != null) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance(getRuntime()).encode(imagePath));
image.setImage(getNewImage(imagePath));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
setPageComplete(isComplete());
}
}
}
public void mouseDown(MouseEvent arg0) {
}
public void mouseUp(MouseEvent arg0) {
}
});
Menu m = new Menu(image);
MenuItem mi = new MenuItem(m, SWT.PUSH);
mi.setText(m_i18n.getString(getNamespace(), "remove", "label", m_language));
mi.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, "");
image.setImage(getNewImage(""));
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
// check if number image exist
if (m_caller != null && m_caller.getPhoneNumber().getTelephoneNumber().length() > 0) {
File photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
if (photo.exists()) {
photo.delete();
}
photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".png");
if (photo.exists()) {
photo.delete();
}
}
setPageComplete(isComplete());
}
});
image.setMenu(m);
final Button gravatar = new Button(t, SWT.CHECK);
gravatar.setText(this.m_i18n.getString(this.getNamespace(), "gravatar", "label", this.m_language));
gravatar.setSelection(this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR));
this.m_useGRAVATAR = this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR);
gravatar.setEnabled(!m_callerReadonly);
gravatar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
m_useGRAVATAR = gravatar.getSelection();
if (m_useGRAVATAR && m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
String email = m_caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue();
if (email != null && email.length() > 0) {
File dir = new File(PathResolver.getInstance().getPhotoDirectory());
if (!dir.exists())
dir.mkdirs();
File img = new File(dir, m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
try {
email = StringUtils.toMD5Hex(email);
String gravatar = "http://www.gravatar.com/avatar/" + email + ".jpg?d=404&s=120";
URL url = new URL(gravatar);
URLConnection c = url.openConnection();
StringBuffer agent = new StringBuffer();
agent.append("jAnrufmonitor Update Manager ");
agent.append(IJAMConst.VERSION_DISPLAY);
c.setDoInput(true);
c.setRequestProperty("User-Agent", agent.toString());
c.connect();
Object o = url.openStream();
if (o instanceof InputStream) {
BufferedInputStream bin = new BufferedInputStream((InputStream) o);
FileOutputStream fos = new FileOutputStream(img);
Stream.copy(bin, fos, true);
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, img.getAbsolutePath());
image.setImage(getNewImage(img.getAbsolutePath()));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
}
} catch (FileNotFoundException ex) {
m_logger.info("No GRAVATAR found: " + ex.getMessage());
} catch (IOException ex) {
m_logger.info("IOException: " + ex.getMessage());
}
}
}
setPageComplete(isComplete());
}
});
} else {
final Button image = new Button(t, SWT.PUSH);
image.setLayoutData(gd);
image.setImage(this.getCallerImage());
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
} else {
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
}
new Label(t, SWT.NONE);
image.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (!m_callerReadonly) {
FileDialog fde = new FileDialog(getShell(), SWT.OPEN);
fde.setFilterExtensions(new String[] { "*.jpg", "*.jpeg", "*.gif", "*.png" });
fde.setText(m_i18n.getString(getNamespace(), "select", "label", m_language));
fde.setFilterPath(PathResolver.getInstance(getRuntime()).resolve(getAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)));
String imagePath = fde.open();
if (imagePath != null) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance(getRuntime()).encode(imagePath));
image.setImage(getNewImage(imagePath));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
setPageComplete(isComplete());
}
}
}
});
Menu m = new Menu(image);
MenuItem mi = new MenuItem(m, SWT.PUSH);
mi.setText(m_i18n.getString(getNamespace(), "remove", "label", m_language));
mi.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, "");
image.setImage(getNewImage(""));
image.setToolTipText(m_i18n.getString(getNamespace(), "pixel", "label", m_language));
// check if number image exist
if (m_caller != null && m_caller.getPhoneNumber().getTelephoneNumber().length() > 0) {
File photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
if (photo.exists()) {
photo.delete();
}
photo = new File(PathResolver.getInstance().getPhotoDirectory(), m_caller.getPhoneNumber().getTelephoneNumber() + ".png");
if (photo.exists()) {
photo.delete();
}
}
setPageComplete(isComplete());
}
});
image.setMenu(m);
final Button gravatar = new Button(t, SWT.CHECK);
gravatar.setText(this.m_i18n.getString(this.getNamespace(), "gravatar", "label", this.m_language));
gravatar.setSelection(this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR));
this.m_useGRAVATAR = this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GRAVATAR);
gravatar.setEnabled(!m_callerReadonly);
gravatar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
m_useGRAVATAR = gravatar.getSelection();
// }
if (m_useGRAVATAR && m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
String email = m_caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue();
if (email != null && email.length() > 0) {
File dir = new File(PathResolver.getInstance().getPhotoDirectory());
if (!dir.exists())
dir.mkdirs();
File img = new File(dir, m_caller.getPhoneNumber().getTelephoneNumber() + ".jpg");
try {
email = StringUtils.toMD5Hex(email);
String gravatar = "http://www.gravatar.com/avatar/" + email + ".jpg?d=404&s=120";
URL url = new URL(gravatar);
URLConnection c = url.openConnection();
StringBuffer agent = new StringBuffer();
agent.append("jAnrufmonitor Update Manager ");
agent.append(IJAMConst.VERSION_DISPLAY);
c.setDoInput(true);
c.setRequestProperty("User-Agent", agent.toString());
c.connect();
Object o = url.openStream();
if (o instanceof InputStream) {
BufferedInputStream bin = new BufferedInputStream((InputStream) o);
FileOutputStream fos = new FileOutputStream(img);
Stream.copy(bin, fos, true);
setAttributeValue(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, img.getAbsolutePath());
image.setImage(getNewImage(img.getAbsolutePath()));
if (hasCallerImage()) {
image.setToolTipText(getCallerImagePath());
}
}
} catch (FileNotFoundException ex) {
m_logger.info("No GRAVATAR found: " + ex.getMessage());
} catch (IOException ex) {
m_logger.info("IOException: " + ex.getMessage());
}
}
}
setPageComplete(isComplete());
}
});
}
// NUMBER DATA
Composite c1 = new Composite(c, SWT.NONE);
c1.setLayout(new GridLayout(1, false));
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 40 : 0);
gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
c1.setLayoutData(gd);
tabFolder = new TabFolder(c1, SWT.BORDER);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 40 : 0);
gd.heightHint = 65 + ("true".equalsIgnoreCase(System.getProperty(IJAMConst.SYSTEM_UI_4K, "false")) ? 20 : 0);
// gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
tabFolder.setLayoutData(gd);
tabFolder.setFocus();
List phones = m_caller.getPhonenumbers();
for (int i = 0, j = phones.size(); i < j; i++) {
new NumberView((IPhonenumber) phones.get(i), this.m_caller.getAttributes(), tabFolder, m_i18n.getString(getNamespace(), "std_phone", "label", m_language)).render();
}
tabFolder.pack();
if (!this.m_callerReadonly && !m_caller.getPhoneNumber().isClired()) {
// selectButton
gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
Composite bc = new Composite(c1, SWT.NONE);
bc.setLayout(new GridLayout(2, false));
final Button addPhone = new Button(bc, SWT.PUSH);
addPhone.setLayoutData(gd);
addPhone.setText(m_i18n.getString(getNamespace(), "add_phone", "label", m_language));
addPhone.setVisible(!m_numberReadonly);
final Button removePhone = new Button(bc, SWT.PUSH);
removePhone.setLayoutData(gd);
removePhone.setText(m_i18n.getString(getNamespace(), "remove_phone", "label", m_language));
removePhone.setEnabled(false);
removePhone.setVisible(!m_numberReadonly);
addPhone.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (tabFolder.getItemCount() < 6) {
new NumberView(getRuntime().getCallerFactory().createPhonenumber(true), m_caller.getAttributes(), tabFolder, m_i18n.getString(getNamespace(), "std_phone", "label", m_language)).render();
tabFolder.setSelection(tabFolder.getItemCount() - 1);
} else
addPhone.setEnabled(false);
removePhone.setEnabled(true);
setPageComplete(isComplete());
}
});
removePhone.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TabItem[] items = tabFolder.getSelection();
if (items.length == 1 && tabFolder.getItemCount() > 1)
items[0].dispose();
addPhone.setEnabled(true);
removePhone.setEnabled(tabFolder.getItemCount() > 1);
setPageComplete(isComplete());
}
});
if (tabFolder.getItemCount() > 1)
removePhone.setEnabled(true);
// new Label(c, SWT.NONE);
// CATEGORIES
Group categoryGroup = new Group(c, SWT.SHADOW_ETCHED_IN);
categoryGroup.setText(this.m_i18n.getString(getNamespace(), "categorygroup", "label", this.m_language));
categoryGroup.setLayout(new GridLayout(2, true));
categoryGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
categoryGroup.setToolTipText(m_i18n.getString(getNamespace(), "tooltipprefix", "label", m_language) + IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_PREFIX + IJAMConst.ATTRIBUTE_NAME_CATEGORY + IJAMConst.GLOBAL_VARIABLE_ATTRIBUTE_POSTFIX);
IAttribute category = this.m_caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
final Combo categoryCombo = new Combo(categoryGroup, SWT.READ_ONLY);
String categories = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(Editor.NAMESPACE, "categories");
String[] tmp = categories.split(",");
String[] categoryList = new String[tmp.length + 1];
categoryList[0] = "";
for (int i = tmp.length - 1, k = 1; i >= 0; i--, k++) {
categoryList[k] = tmp[i];
}
int select = 0;
for (int i = 0; i < categoryList.length; i++) {
categoryCombo.setData(categoryList[i], categoryList[i]);
if (category != null && categoryList[i].equalsIgnoreCase(category.getValue())) {
select = i;
}
}
categoryCombo.setItems(categoryList);
categoryCombo.select(select);
// Add the handler to update the name based on input
categoryCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String scat = categoryCombo.getItem(categoryCombo.getSelectionIndex());
m_caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, scat));
if (scat == null || scat.trim().length() == 0) {
m_caller.getAttributes().remove(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
}
setPageComplete(isComplete());
}
});
}
c.pack();
setPageComplete(isComplete());
setControl(c);
}
Aggregations