use of org.eclipse.ui.cheatsheets.AbstractItemExtensionElement in project org.eclipse.rap by eclipse-rap.
the class CheatSheetParser method handleUnknownItemAttribute.
private AbstractItemExtensionElement[] handleUnknownItemAttribute(Node item, Node node) {
ArrayList al = new ArrayList();
if (itemExtensionContainerList == null)
return null;
for (int i = 0; i < itemExtensionContainerList.size(); i++) {
CheatSheetItemExtensionElement itemExtensionElement = (CheatSheetItemExtensionElement) itemExtensionContainerList.get(i);
if (itemExtensionElement.getItemAttribute().equals(item.getNodeName())) {
AbstractItemExtensionElement itemElement = itemExtensionElement.createInstance();
if (itemElement != null) {
itemElement.handleAttribute(item.getNodeValue());
al.add(itemElement);
}
}
}
if (al.size() == 0) {
String message = NLS.bind(Messages.get().WARNING_PARSING_UNKNOWN_ATTRIBUTE, (new Object[] { item.getNodeName(), node.getNodeName() }));
addStatus(IStatus.WARNING, message, null);
}
return (AbstractItemExtensionElement[]) al.toArray(new AbstractItemExtensionElement[al.size()]);
}
use of org.eclipse.ui.cheatsheets.AbstractItemExtensionElement in project org.eclipse.rap by eclipse-rap.
the class CheatSheetParser method handleItemAttributes.
private void handleItemAttributes(Item item, Node itemNode) throws CheatSheetParserException {
Assert.isNotNull(item);
Assert.isNotNull(itemNode);
ArrayList itemExtensionElements = new ArrayList();
boolean title = false;
NamedNodeMap attributes = itemNode.getAttributes();
if (attributes != null) {
for (int x = 0; x < attributes.getLength(); x++) {
Node attribute = attributes.item(x);
String attributeName = attribute.getNodeName();
if (attribute == null || attributeName == null)
continue;
if (attributeName.equals(IParserTags.TITLE)) {
title = true;
item.setTitle(attribute.getNodeValue());
} else if (attributeName.equals(IParserTags.CONTEXTID)) {
item.setContextId(attribute.getNodeValue());
} else if (attributeName.equals(IParserTags.HREF)) {
item.setHref(attribute.getNodeValue());
} else if (attributeName.equals(IParserTags.SKIP)) {
item.setSkip(attribute.getNodeValue().equals(TRUE_STRING));
} else if (attributeName.equals(IParserTags.DIALOG)) {
item.setDialog(attribute.getNodeValue().equals(TRUE_STRING));
} else {
AbstractItemExtensionElement[] ie = handleUnknownItemAttribute(attribute, itemNode);
if (ie != null) {
itemExtensionElements.add(ie);
} else {
String message = NLS.bind(Messages.get().WARNING_PARSING_UNKNOWN_ATTRIBUTE, (new Object[] { attributeName, itemNode.getNodeName() }));
addStatus(IStatus.WARNING, message, null);
}
}
}
}
if (!title) {
String message = NLS.bind(Messages.get().ERROR_PARSING_NO_TITLE, (new Object[] { itemNode.getNodeName() }));
throw new CheatSheetParserException(message);
}
if (itemExtensionElements != null)
item.setItemExtensions(itemExtensionElements);
}
use of org.eclipse.ui.cheatsheets.AbstractItemExtensionElement in project org.eclipse.rap by eclipse-rap.
the class CheatSheetItemExtensionElement method createInstance.
public AbstractItemExtensionElement createInstance() {
Class extClass = null;
AbstractItemExtensionElement extElement = null;
String pluginId = configurationElement.getContributor().getName();
try {
Bundle bundle = Platform.getBundle(pluginId);
extClass = bundle.loadClass(className);
} catch (Exception e) {
String message = NLS.bind(Messages.get().ERROR_LOADING_CLASS, (new Object[] { className }));
IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
CheatSheetPlugin.getPlugin().getLog().log(status);
}
try {
if (extClass != null) {
Constructor c = extClass.getConstructor(stringArray);
Object[] parameters = { itemAttribute };
extElement = (AbstractItemExtensionElement) c.newInstance(parameters);
}
} catch (Exception e) {
String message = NLS.bind(Messages.get().ERROR_CREATING_CLASS, (new Object[] { className }));
IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
CheatSheetPlugin.getPlugin().getLog().log(status);
}
if (extElement != null) {
return extElement;
}
return null;
}
use of org.eclipse.ui.cheatsheets.AbstractItemExtensionElement in project org.eclipse.rap by eclipse-rap.
the class ViewItem method addItem.
// Adds the item to the main composite.
private void addItem() {
// $NON-NLS-1$
CheatSheetStopWatch.startStopWatch("ViewItem.addItem()");
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after getBannerBackground: ");
// Set up the main composite for the item.******************************************
// $NON-NLS-1$
checkDoneLabel = page.getToolkit().createLabel(parent, " ");
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after create checkDoneLabel: ");
mainItemComposite = page.getToolkit().createSection(parent, ExpandableComposite.TWISTIE | ExpandableComposite.COMPACT);
mainItemComposite.setBackground(itemColor);
mainItemComposite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
String title = item.getTitle();
if (title != null) {
mainItemComposite.setText(ViewUtilities.escapeForLabel(title));
}
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after create mainItemComposite: ");
mainItemComposite.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
page.getForm().reflow(true);
}
});
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after addExpansionListener: ");
// handle item extensions here
// check number of extensions for this item and adjust layout accordingly
int number = 0;
ArrayList itemExts = item.getItemExtensions();
if ((itemExts != null && itemExts.size() > 0) || item.getContextId() != null || item.getHref() != null) {
// Set up the title composite for the item.
titleComposite = page.getToolkit().createComposite(mainItemComposite);
titleComposite.setBackground(itemColor);
}
if (itemExts != null) {
for (int g = 0; g < itemExts.size(); g++) {
AbstractItemExtensionElement[] eea = (AbstractItemExtensionElement[]) itemExts.get(g);
number += eea.length;
for (int x = 0; x < eea.length; x++) {
eea[x].createControl(titleComposite);
}
}
}
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after create item extensions: ");
// don't add the help icon unless there is a context id or help link
if (item.getContextId() != null || item.getHref() != null) {
// adjust the layout count
number++;
ImageHyperlink helpButton = createButton(titleComposite, CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.CHEATSHEET_ITEM_HELP), this, itemColor, Messages.get().HELP_BUTTON_TOOLTIP);
helpButton.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
// If we have a context id, handle this first and ignore an hrefs
if (item.getContextId() != null) {
openInfopop(e.widget);
} else {
// We only have an href, so let's open it in the help system
openHelpTopic();
}
}
});
}
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after create help button: ");
if (number > 0) {
mainItemComposite.setTextClient(titleComposite);
GridLayout layout = new GridLayout(number, false);
GridData data = new GridData(GridData.FILL_BOTH);
titleComposite.setLayout(layout);
titleComposite.setLayoutData(data);
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.verticalSpacing = 0;
}
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after setTextClient: ");
// Body wrapper here. this composite will be hidden and shown as appropriate.
bodyWrapperComposite = page.getToolkit().createComposite(mainItemComposite);
mainItemComposite.setClient(bodyWrapperComposite);
TableWrapLayout wrapperLayout = new TableWrapLayout();
bodyWrapperComposite.setLayout(wrapperLayout);
bodyWrapperComposite.setBackground(itemColor);
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after create bodyWrapperComposite: ");
bodyText = page.getToolkit().createFormText(bodyWrapperComposite, false);
// RAP [if] Clipboard
// bodyText.addSelectionListener(new SelectionAdapter() {
// public void widgetSelected(SelectionEvent e) {
// Action copyAction = viewer.getCopyAction();
// if (copyAction!=null)
// copyAction.setEnabled(bodyText.canCopy());
// }
// });
// bodyText.addFocusListener(new FocusListener() {
// public void focusGained(FocusEvent e) {
// Action copyAction = viewer.getCopyAction();
// if (copyAction!=null)
// copyAction.setEnabled(bodyText.canCopy());
// }
// public void focusLost(FocusEvent e) {
// Action copyAction = viewer.getCopyAction();
// if (copyAction!=null)
// copyAction.setEnabled(false);
// }
// });
// bodyText = toolkit.createLabel(bodyWrapperComposite, item.getDescription(), SWT.WRAP);
bodyText.setText(item.getDescription(), item.getDescription().startsWith(IParserTags.FORM_START_TAG), false);
// Set up the body text portion here.
bodyText.setBackground(itemColor);
bodyText.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after create FormText: ");
if (!item.isDynamic()) {
handleButtons();
}
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after handleButtons(): ");
setButtonsVisible(false);
setCollapsed();
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after setting buttons and item collapsed: ");
boldFont = mainItemComposite.getFont();
FontData[] fontDatas = boldFont.getFontData();
// RAP [if] FontData#setStyle is not supported
// for (int i = 0; i < fontDatas.length; i++) {
// fontDatas[i].setStyle(fontDatas[i].getStyle() ^ SWT.BOLD);
// }
// RAP [if] We supports only fontData arrays with one element
// regularFont = new Font(mainItemComposite.getDisplay(), fontDatas);
regularFont = Graphics.getFont(fontDatas[0].getName(), fontDatas[0].getHeight(), fontDatas[0].getStyle() ^ SWT.BOLD);
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after font initlization: ");
setBold(false);
// $NON-NLS-1$ //$NON-NLS-2$
CheatSheetStopWatch.printLapTime("ViewItem.addItem()", "Time in addItem() after setBold: ");
}
Aggregations