use of org.eclipse.jface.action.ToolBarManager in project netxms by netxms.
the class ApplicationActionBarAdvisor method fillCoolBar.
/* (non-Javadoc)
* @see org.eclipse.ui.application.ActionBarAdvisor#fillCoolBar(org.eclipse.jface.action.ICoolBarManager)
*/
@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.TRAIL);
toolbar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
// $NON-NLS-1$
coolBar.add(new ToolBarContributionItem(toolbar, "product"));
toolbar = new ToolBarManager(SWT.FLAT | SWT.TRAIL);
toolbar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
// $NON-NLS-1$
coolBar.add(new ToolBarContributionItem(toolbar, "view"));
toolbar = new ToolBarManager(SWT.FLAT | SWT.TRAIL);
toolbar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
// $NON-NLS-1$
coolBar.add(new ToolBarContributionItem(toolbar, "logs"));
toolbar = new ToolBarManager(SWT.FLAT | SWT.TRAIL);
toolbar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
// $NON-NLS-1$
coolBar.add(new ToolBarContributionItem(toolbar, "tools"));
toolbar = new ToolBarManager(SWT.FLAT | SWT.TRAIL);
toolbar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
// $NON-NLS-1$
coolBar.add(new ToolBarContributionItem(toolbar, "config"));
if (// $NON-NLS-1$
Activator.getDefault().getPreferenceStore().getBoolean("SHOW_SERVER_CLOCK")) {
coolBar.add(new ServerClockContributionItem());
}
// $NON-NLS-1$
ConsoleSharedData.setProperty("CoolBarManager", coolBar);
}
use of org.eclipse.jface.action.ToolBarManager in project core by jcryptool.
the class ApplicationActionBarAdvisor method fillCoolBar.
@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
// ToolBar File & Additions
IToolBarManager fileToolBar = new ToolBarManager(coolBar.getStyle());
IServiceLocator serviceLocator = PlatformUI.getWorkbench();
fileToolBar.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
fileToolBar.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.FILE_SAVE));
fileToolBar.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.FILE_SAVE_ALL));
fileToolBar.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.FILE_PRINT));
fileToolBar.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
fileToolBar.add(new Separator());
fileToolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
// $NON-NLS-1$
coolBar.add(new ToolBarContributionItem(fileToolBar, CorePlugin.PLUGIN_ID + ".toolbar"));
// ToolBar Help
IToolBarManager helpToolBar = new ToolBarManager(coolBar.getStyle());
// $NON-NLS-1$
coolBar.add(new ToolBarContributionItem(helpToolBar, CorePlugin.PLUGIN_ID + ".helpToolBar"));
// CoolBar Context Menu
// $NON-NLS-1$
MenuManager coolBarContextMenuManager = new MenuManager(null, CorePlugin.PLUGIN_ID + ".contextMenu");
coolBar.setContextMenuManager(coolBarContextMenuManager);
coolBarContextMenuManager.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.WINDOW_LOCK_TOOLBAR));
coolBarContextMenuManager.add(createContributionItem(serviceLocator, null, IWorkbenchCommandConstants.WINDOW_CUSTOMIZE_PERSPECTIVE));
coolBarContextMenuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
use of org.eclipse.jface.action.ToolBarManager in project rap by entirej.
the class EJRWTMultiRecordBlockRenderer method buildGuiComponent.
@Override
public void buildGuiComponent(EJRWTEntireJGridPane blockCanvas) {
EJFrameworkExtensionProperties appProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
if (appProp != null) {
EJFrameworkExtensionProperties propertyGroup = appProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
if (propertyGroup != null) {
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY);
}
}
EJBlockProperties blockProperties = _block.getProperties();
EJMainScreenProperties mainScreenProperties = blockProperties.getMainScreenProperties();
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = mainScreenProperties.getWidth();
gridData.heightHint = mainScreenProperties.getHeight();
gridData.horizontalSpan = mainScreenProperties.getHorizontalSpan();
gridData.verticalSpan = mainScreenProperties.getVerticalSpan();
gridData.grabExcessHorizontalSpace = mainScreenProperties.canExpandHorizontally();
gridData.grabExcessVerticalSpace = mainScreenProperties.canExpandVertically();
if (gridData.grabExcessHorizontalSpace) {
gridData.minimumWidth = mainScreenProperties.getWidth();
}
if (gridData.grabExcessVerticalSpace) {
gridData.minimumHeight = mainScreenProperties.getHeight();
}
EJFrameworkExtensionProperties rendererProp = blockProperties.getBlockRendererProperties();
blockCanvas.setLayoutData(gridData);
EJFrameworkExtensionProperties sectionProperties = null;
if (rendererProp != null) {
sectionProperties = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR);
}
if (sectionProperties != null && sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
int style = ExpandableComposite.TITLE_BAR;
String mode = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
style = style | ExpandableComposite.TWISTIE;
} else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
style = style | ExpandableComposite.TREE_NODE;
}
if (sectionProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
style = style | ExpandableComposite.EXPANDED;
}
Section section = toolkit.createSection(blockCanvas, style);
section.setLayoutData(gridData);
String title = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_TITLE);
if (title != null) {
section.setText(title);
}
String frameTitle = mainScreenProperties.getFrameTitle();
EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
Group group = new Group(section, SWT.NONE);
group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
group.setLayout(new FillLayout());
group.setLayoutData(gridData);
hookKeyListener(group);
group.setText(frameTitle);
_mainPane = new EJRWTEntireJGridPane(group, 1);
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
section.setClient(group);
} else {
_mainPane = new EJRWTEntireJGridPane(section, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
_mainPane.setLayoutData(gridData);
if (!mainScreenProperties.getDisplayFrame())
_mainPane.cleanLayoutHorizontal();
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
section.setClient(_mainPane);
}
final EJFrameworkExtensionPropertyList propertyList = sectionProperties.getPropertyList(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTIONS);
if (propertyList != null && propertyList.getAllListEntries().size() > 0) {
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
final ToolBar toolbar = toolBarManager.createControl(section);
final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
toolbar.setCursor(handCursor);
// Cursor needs to be explicitly disposed
toolbar.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (handCursor != null && handCursor.isDisposed() == false) {
handCursor.dispose();
}
}
});
List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
final String actionID = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_ID);
String actionImage = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_IMAGE);
String actionName = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_NAME);
String actionTooltip = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_TOOLTIP);
if (actionID != null) {
Action action = new Action(actionID, IAction.AS_PUSH_BUTTON) {
@Override
public void runWithEvent(Event event) {
_block.executeActionCommand(actionID, EJScreenType.MAIN);
}
};
if (actionName != null) {
action.setText(actionName);
}
if (actionTooltip != null) {
action.setDescription(actionTooltip);
}
if (actionImage != null && actionImage.length() > 0) {
action.setImageDescriptor(ImageDescriptor.createFromImage(EJRWTImageRetriever.get(actionImage)));
}
toolBarManager.add(action);
}
}
toolBarManager.update(true);
section.setTextClient(toolbar);
}
} else {
String frameTitle = mainScreenProperties.getFrameTitle();
if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
Group group = new Group(blockCanvas, SWT.NONE);
group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
group.setLayout(new FillLayout());
group.setLayoutData(gridData);
hookKeyListener(group);
group.setText(frameTitle);
_mainPane = new EJRWTEntireJGridPane(group, 1);
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
} else {
_mainPane = new EJRWTEntireJGridPane(blockCanvas, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
_mainPane.setLayoutData(gridData);
if (!mainScreenProperties.getDisplayFrame())
_mainPane.cleanLayout();
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
}
}
hookKeyListener(_mainPane);
int style = SWT.VIRTUAL;
if (!rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.HIDE_TABLE_BORDER, false)) {
style = style | SWT.BORDER;
}
if (rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ROW_SELECTION_PROPERTY, true)) {
style = style | SWT.FULL_SELECTION;
} else {
style = style | SWT.HIDE_SELECTION;
}
Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
final Table table;
final boolean hideSelection = (style & SWT.HIDE_SELECTION) != 0;
final EJRWTAbstractFilteredTable filterTree;
if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, false)) {
if (allItemGroupProperties.size() > 0) {
EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
Group group = new Group(_mainPane, SWT.NONE);
group.setLayout(new FillLayout());
group.setText(displayProperties.getFrameTitle());
group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
filterTree = new EJRWTAbstractFilteredTable(group, style) {
@Override
public void filter(String filter) {
if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
_filteredContentProvider.setFilter(filter);
getViewer().setInput(filter);
if (getFocusedRecord() == null) {
selectRow(0);
}
notifyStatus();
}
}
@Override
protected TableViewer doCreateTableViewer(Composite parent, int style) {
return _tableViewer = new TableViewer(parent) {
private static final long serialVersionUID = 5803610958722645987L;
@Override
public void setSelection(ISelection selection) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection, reveal);
}
};
}
};
} else {
filterTree = new EJRWTAbstractFilteredTable(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : style) {
@Override
public void filter(String filter) {
if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
_filteredContentProvider.setFilter(filter);
getViewer().setInput(filter);
if (getFocusedRecord() == null) {
selectRow(0);
}
notifyStatus();
}
}
@Override
protected TableViewer doCreateTableViewer(Composite parent, int style) {
return _tableViewer = new TableViewer(parent) {
private static final long serialVersionUID = 5803610958722645987L;
@Override
public void setSelection(ISelection selection) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection, reveal);
}
};
}
};
filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
} else {
filterTree = new EJRWTAbstractFilteredTable(_mainPane, style) {
@Override
public void filter(String filter) {
if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
_filteredContentProvider.setFilter(filter);
getViewer().setInput(filter);
if (getFocusedRecord() == null) {
selectRow(0);
}
notifyStatus();
}
}
@Override
protected TableViewer doCreateTableViewer(Composite parent, int style) {
return _tableViewer = new TableViewer(parent) {
private static final long serialVersionUID = 5803610958722645987L;
@Override
public void setSelection(ISelection selection) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection, reveal);
}
};
}
};
filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
table = (_tableViewer = filterTree.getViewer()).getTable();
} else {
filterTree = null;
if (allItemGroupProperties.size() > 0) {
EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
Group group = new Group(_mainPane, SWT.NONE);
group.setLayout(new FillLayout());
group.setText(displayProperties.getFrameTitle());
group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
table = new Table(group, style);
} else {
table = new Table(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : style);
table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
} else {
table = new Table(_mainPane, style);
table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
_tableViewer = new TableViewer(table) {
@Override
public void setSelection(ISelection selection) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection);
}
@Override
public void setSelection(ISelection selection, boolean reveal) {
if (hideSelection) {
selection = new StructuredSelection();
}
super.setSelection(selection, reveal);
}
};
}
table.setLinesVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_VERTICAL_LINES, true));
table.setHeaderVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_HEADING_PROPERTY, true));
int fixedColumns = rendererProp.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.COLUMNS_FIXED, -1);
if (fixedColumns > 0) {
table.setData(EJ_RWT.FIXED_COLUMNS, fixedColumns);
}
int rowHeight = rendererProp.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_HEIGH_PROPERTY, -1);
if (rowHeight > 0) {
table.setData(EJ_RWT.CUSTOM_ITEM_HEIGHT, rowHeight);
}
Control[] children = table.getChildren();
for (Control control : children) {
hookKeyListener(control);
}
hookKeyListener(table);
EJRWTTableViewerColumnFactory factory = new EJRWTTableViewerColumnFactory(_tableViewer);
ColumnViewerToolTipSupport.enableFor(_tableViewer);
boolean autoSize = false;
final List<ColumnLabelProvider> nodeTextProviders = new ArrayList<ColumnLabelProvider>();
for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
autoSize = itemProperties.size() == 1;
for (EJScreenItemProperties screenItemProperties : itemProperties) {
EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
ColumnLabelProvider screenItem = createScreenItem(factory, mainScreenItemProperties);
if (screenItem != null) {
nodeTextProviders.add(screenItem);
if (autoSize) {
EJFrameworkExtensionProperties itemBl = mainScreenItemProperties.getBlockRendererRequiredProperties();
autoSize = itemBl != null && itemBl.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_WIDTH_PROPERTY, 0) <= 0;
}
}
}
}
if (autoSize) {
table.addControlListener(new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
if (table.getSize().x > 10) {
table.getColumn(0).setWidth(table.getSize().x - 10);
}
}
@Override
public void controlMoved(ControlEvent e) {
// TODO Auto-generated method stub
}
});
}
table.setData(EJ_RWT.MARKUP_ENABLED, Boolean.TRUE);
table.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0) {
setHasFocus(false);
}
@Override
public void focusGained(FocusEvent arg0) {
setHasFocus(true);
}
});
_mainPane.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
if (!table.isFocusControl()) {
setHasFocus(true);
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
if (!table.isFocusControl()) {
setHasFocus(true);
}
}
});
_tableViewer.setContentProvider(_filteredContentProvider = new FilteredContentProvider() {
boolean matchItem(EJDataRecord rec) {
if (filter != null && filter.trim().length() > 0) {
for (ColumnLabelProvider filterTextProvider : nodeTextProviders) {
String text = filterTextProvider.getText(rec);
if (text != null && text.toLowerCase().contains(filter.toLowerCase())) {
return true;
}
}
}
return false;
}
@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
_tableBaseRecords.clear();
if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
// filter
for (EJDataRecord record : _block.getBlock().getRecords()) {
if (matchItem(record)) {
_tableBaseRecords.add(record);
}
}
} else {
filter = null;
if (filterTree != null) {
filterTree.clearText();
}
_tableBaseRecords.addAll(_block.getBlock().getRecords());
}
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object arg0) {
return _tableBaseRecords.toArray();
}
});
_tableViewer.setInput(new Object());
selectRow(0);
// add double click action
final String doubleClickActionCommand = rendererProp.getStringProperty(EJRWTMultiRecordBlockDefinitionProperties.DOUBLE_CLICK_ACTION_COMMAND);
if (doubleClickActionCommand != null) {
_tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent arg0) {
_block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
}
});
}
_tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent arg0) {
EJDataRecord focusedRecord = getFocusedRecord();
if (focusedRecord != null) {
_block.newRecordInstance(focusedRecord);
}
notifyStatus();
}
});
table.addListener(SWT.MouseDown, new Listener() {
@Override
public void handleEvent(Event event) {
Point pt = new Point(event.x, event.y);
TableItem item = table.getItem(pt);
if (item == null || item.isDisposed())
return;
for (int i = 0; i < table.getColumnCount(); i++) {
if (item == null || item.isDisposed())
return;
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
TableColumn column = table.getColumn(i);
if (column != null && column.getData("ITEM") instanceof EJScreenItemController) {
((EJScreenItemController) column.getData("ITEM")).executeActionCommand();
}
}
}
}
});
}
use of org.eclipse.jface.action.ToolBarManager in project rap by entirej.
the class EJRWTSingleRecordBlockRenderer method createItemGroup.
private void createItemGroup(Composite parent, EJItemGroupProperties groupProperties) {
EJRWTEntireJGridPane groupPane;
String frameTitle = groupProperties.getFrameTitle();
EJFrameworkExtensionProperties rendererProperties = groupProperties.getRendererProperties();
boolean hasGroup = groupProperties.dispayGroupFrame() && frameTitle != null && frameTitle.length() > 0;
if (hasGroup) {
if (rendererProperties != null && rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
int style = ExpandableComposite.TITLE_BAR;
String mode = rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
style = style | ExpandableComposite.TWISTIE;
} else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
style = style | ExpandableComposite.TREE_NODE;
}
if (rendererProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
style = style | ExpandableComposite.EXPANDED;
}
Section section = toolkit.createSection(parent, style);
section.setText(frameTitle);
EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
section.setLayoutData(createItemGroupGridData(groupProperties));
parent = section;
hookKeyListener(section);
section.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
setHasFocus(true);
}
});
groupPane = new EJRWTEntireJGridPane(parent, groupProperties.getNumCols());
groupPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
String customCSSKey = rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_CSS_KEY);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
groupPane.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
// groupPane.getLayout().marginRight = 5;
// groupPane.getLayout().marginLeft = 5;
section.setClient(groupPane);
final EJFrameworkExtensionPropertyList propertyList = rendererProperties.getPropertyList(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTIONS);
if (propertyList != null && propertyList.getAllListEntries().size() > 0) {
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
final ToolBar toolbar = toolBarManager.createControl(section);
final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
toolbar.setCursor(handCursor);
// Cursor needs to be explicitly disposed
toolbar.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (handCursor != null && handCursor.isDisposed() == false) {
handCursor.dispose();
}
}
});
List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
final String actionID = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_ID);
String actionImage = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_IMAGE);
String actionName = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_NAME);
String actionTooltip = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_TOOLTIP);
if (actionID != null) {
Action action = new Action(actionID, IAction.AS_PUSH_BUTTON) {
@Override
public void runWithEvent(Event event) {
_block.executeActionCommand(actionID, EJScreenType.MAIN);
}
};
if (actionName != null) {
action.setText(actionName);
}
if (actionTooltip != null) {
action.setDescription(actionTooltip);
}
if (actionImage != null && actionImage.length() > 0) {
action.setImageDescriptor(ImageDescriptor.createFromImage(EJRWTImageRetriever.get(actionImage)));
}
toolBarManager.add(action);
}
}
toolBarManager.update(true);
section.setTextClient(toolbar);
}
} else {
Composite group = new Composite(parent, groupProperties.dispayGroupFrame() ? SWT.BORDER : SWT.NONE);
group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
String customCSSKey = rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_CSS_KEY);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
group.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
group.setLayout(new FillLayout());
group.setLayoutData(createItemGroupGridData(groupProperties));
parent = group;
hookKeyListener(group);
group.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
setHasFocus(true);
}
});
groupPane = new EJRWTEntireJGridPane(parent, groupProperties.getNumCols());
groupPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
groupPane.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
// groupPane.getLayout().marginRight = 5;
// groupPane.getLayout().marginLeft = 5;
}
} else {
groupPane = new EJRWTEntireJGridPane(parent, groupProperties.getNumCols(), groupProperties.dispayGroupFrame() ? SWT.BORDER : SWT.NONE);
groupPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
if (rendererProperties != null) {
String customCSSKey = rendererProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_CSS_KEY);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
groupPane.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
}
if (groupProperties.dispayGroupFrame()) {
// groupPane.getLayout().marginRight = 5;
// groupPane.getLayout().marginLeft = 5;
}
}
groupPane.getLayout().verticalSpacing = 1;
hookKeyListener(groupPane);
groupPane.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
setHasFocus(true);
}
});
groupPane.setPaneName(groupProperties.getName());
if (!hasGroup) {
groupPane.setLayoutData(createItemGroupGridData(groupProperties));
}
// items adding
Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
for (EJScreenItemProperties screenItemProperties : itemProperties) {
createScreenItem(groupPane, (EJCoreMainScreenItemProperties) screenItemProperties);
}
// build sub groups
EJItemGroupPropertiesContainer groupPropertiesContainer = groupProperties.getChildItemGroupContainer();
Collection<EJItemGroupProperties> itemGroupProperties = groupPropertiesContainer.getAllItemGroupProperties();
for (EJItemGroupProperties ejItemGroupProperties : itemGroupProperties) {
createItemGroup(groupPane, ejItemGroupProperties);
}
}
use of org.eclipse.jface.action.ToolBarManager in project rap by entirej.
the class EJRWTTreeRecordBlockRenderer method buildGuiComponent.
@Override
public void buildGuiComponent(EJRWTEntireJGridPane blockCanvas) {
EJFrameworkExtensionProperties appProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
if (appProp != null) {
EJFrameworkExtensionProperties propertyGroup = appProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
if (propertyGroup != null) {
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY);
addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY);
}
}
EJBlockProperties blockProperties = _block.getProperties();
EJMainScreenProperties mainScreenProperties = blockProperties.getMainScreenProperties();
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = mainScreenProperties.getWidth();
gridData.heightHint = mainScreenProperties.getHeight();
gridData.horizontalSpan = mainScreenProperties.getHorizontalSpan();
gridData.verticalSpan = mainScreenProperties.getVerticalSpan();
gridData.grabExcessHorizontalSpace = mainScreenProperties.canExpandHorizontally();
gridData.grabExcessVerticalSpace = mainScreenProperties.canExpandVertically();
if (gridData.grabExcessHorizontalSpace) {
gridData.minimumWidth = mainScreenProperties.getWidth();
}
if (gridData.grabExcessVerticalSpace) {
gridData.minimumHeight = mainScreenProperties.getHeight();
}
rendererProp = blockProperties.getBlockRendererProperties();
blockCanvas.setLayoutData(gridData);
EJFrameworkExtensionProperties sectionProperties = null;
if (rendererProp != null) {
sectionProperties = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR);
}
if (sectionProperties != null && sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
int style = ExpandableComposite.TITLE_BAR;
String mode = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
style = style | ExpandableComposite.TWISTIE;
} else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
style = style | ExpandableComposite.TREE_NODE;
}
if (sectionProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
style = style | ExpandableComposite.EXPANDED;
}
Section section = toolkit.createSection(blockCanvas, style);
section.setLayoutData(gridData);
String title = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_TITLE);
if (title != null) {
section.setText(title);
}
EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
String frameTitle = mainScreenProperties.getFrameTitle();
if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
Group group = new Group(section, SWT.NONE);
group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
group.setLayout(new FillLayout());
group.setLayoutData(gridData);
hookKeyListener(group);
group.setText(frameTitle);
_mainPane = new EJRWTEntireJGridPane(group, 1);
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
section.setClient(group);
} else {
_mainPane = new EJRWTEntireJGridPane(section, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
_mainPane.setLayoutData(gridData);
_mainPane.cleanLayoutHorizontal();
section.setClient(_mainPane);
}
final EJFrameworkExtensionPropertyList propertyList = sectionProperties.getPropertyList(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTIONS);
if (propertyList != null && propertyList.getAllListEntries().size() > 0) {
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
final ToolBar toolbar = toolBarManager.createControl(section);
final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
toolbar.setCursor(handCursor);
// Cursor needs to be explicitly disposed
toolbar.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (handCursor != null && handCursor.isDisposed() == false) {
handCursor.dispose();
}
}
});
List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
final String actionID = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_ID);
String actionImage = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_IMAGE);
String actionName = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_NAME);
String actionTooltip = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_TOOLTIP);
if (actionID != null) {
Action action = new Action(actionID, IAction.AS_PUSH_BUTTON) {
@Override
public void runWithEvent(Event event) {
_block.executeActionCommand(actionID, EJScreenType.MAIN);
}
};
if (actionName != null) {
action.setText(actionName);
}
if (actionTooltip != null) {
action.setDescription(actionTooltip);
}
if (actionImage != null && actionImage.length() > 0) {
action.setImageDescriptor(ImageDescriptor.createFromImage(EJRWTImageRetriever.get(actionImage)));
}
toolBarManager.add(action);
}
}
toolBarManager.update(true);
section.setTextClient(toolbar);
}
} else {
String frameTitle = mainScreenProperties.getFrameTitle();
if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
Group group = new Group(blockCanvas, SWT.NONE);
group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
group.setLayout(new FillLayout());
group.setLayoutData(gridData);
hookKeyListener(group);
group.setText(frameTitle);
_mainPane = new EJRWTEntireJGridPane(group, 1);
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
} else {
_mainPane = new EJRWTEntireJGridPane(blockCanvas, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
_mainPane.setLayoutData(gridData);
_mainPane.cleanLayout();
_mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
}
}
hookKeyListener(_mainPane);
int style = SWT.VIRTUAL;
if (!rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.HIDE_TREE_BORDER, false)) {
style = style | SWT.BORDER;
}
if (!rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.HIDE_SELECTION, false)) {
style = style | SWT.FULL_SELECTION;
}
Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
final Tree table;
final EJRWTAbstractFilteredTree filterTree;
if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, true)) {
if (allItemGroupProperties.size() > 0) {
EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
Group group = new Group(_mainPane, SWT.NONE);
group.setLayout(new FillLayout());
group.setText(displayProperties.getFrameTitle());
group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
filterTree = new EJRWTAbstractFilteredTree(group, style) {
@Override
public void filter(String filter) {
if (filteredContentProvider != null && (filter == null && filteredContentProvider.getFilter() != null || !filter.equals(filteredContentProvider.getFilter()))) {
filteredContentProvider.setFilter(filter);
refresh(filter);
}
}
};
} else {
filterTree = new EJRWTAbstractFilteredTree(_mainPane, style) {
@Override
public void filter(String filter) {
if (filteredContentProvider != null && (filter == null && filteredContentProvider.getFilter() != null || !filter.equals(filteredContentProvider.getFilter()))) {
filteredContentProvider.setFilter(filter);
refresh(filter);
}
}
};
filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
} else {
filterTree = new EJRWTAbstractFilteredTree(_mainPane, style) {
@Override
public void filter(String filter) {
if (filteredContentProvider != null && (filter == null && filteredContentProvider.getFilter() != null || !filter.equals(filteredContentProvider.getFilter()))) {
filteredContentProvider.setFilter(filter);
refresh(filter);
}
}
};
filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
table = (_tableViewer = filterTree.getViewer()).getTree();
} else {
filterTree = null;
if (allItemGroupProperties.size() > 0) {
EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
Group group = new Group(_mainPane, SWT.NONE);
group.setLayout(new FillLayout());
group.setText(displayProperties.getFrameTitle());
group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
table = new Tree(group, style);
} else {
table = new Tree(_mainPane, style | (displayProperties.dispayGroupFrame() ? SWT.BORDER : SWT.NONE));
table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
} else {
table = new Tree(_mainPane, style);
table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
}
_tableViewer = new TreeViewer(table);
}
Control[] children = table.getChildren();
for (Control control : children) {
hookKeyListener(control);
}
hookKeyListener(table);
ColumnViewerToolTipSupport.enableFor(_tableViewer);
final List<TreeNodeTextProvider> nodeTextProviders = new ArrayList<EJRWTTreeRecordBlockRenderer.TreeNodeTextProvider>();
for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
for (EJScreenItemProperties screenItemProperties : itemProperties) {
EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
TreeNodeTextProvider screenItem = createScreenItem(mainScreenItemProperties);
if (screenItem != null) {
nodeTextProviders.add(screenItem);
}
}
}
table.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0) {
setHasFocus(false);
}
@Override
public void focusGained(FocusEvent arg0) {
setHasFocus(true);
}
});
_mainPane.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
if (!table.isFocusControl()) {
setHasFocus(true);
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
if (!table.isFocusControl()) {
setHasFocus(true);
}
}
});
final String pid = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.PARENT_ITEM);
final String rid = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.RELATION_ITEM);
final String imageid = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.NODE_IMAGE_ITEM);
final EJCoreVisualAttributeProperties baseVA;
String visualAttribute = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.VISUAL_ATTRIBUTE_PROPERTY);
if (visualAttribute != null) {
baseVA = EJCoreProperties.getInstance().getVisualAttributesContainer().getVisualAttributeProperties(visualAttribute);
} else {
baseVA = null;
}
final Map<Object, Image> imageMap = new HashMap<Object, Image>();
_tableViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public Color getBackground(Object element) {
EJCoreVisualAttributeProperties properties = getAttributes(element);
if (properties != null) {
Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
if (background != null) {
return background;
}
}
return super.getBackground(element);
}
@Override
public Color getForeground(Object element) {
EJCoreVisualAttributeProperties properties = getAttributes(element);
if (properties != null) {
Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
if (foreground != null) {
return foreground;
}
}
return super.getForeground(element);
}
private EJCoreVisualAttributeProperties getAttributes(Object element) {
EJCoreVisualAttributeProperties properties = null;
if (pid != null && element instanceof EJDataRecord) {
EJDataRecord record = (EJDataRecord) element;
properties = record.getItem(pid).getVisualAttribute();
}
if (properties == null) {
properties = baseVA;
}
return properties;
}
@Override
public Font getFont(Object element) {
EJCoreVisualAttributeProperties properties = getAttributes(element);
if (properties != null) {
Font font = super.getFont(element);
return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, font != null ? font : _tableViewer.getTree().getFont());
}
return super.getFont(element);
}
@Override
public Image getImage(Object element) {
if (imageid != null && element instanceof EJDataRecord) {
EJDataRecord record = (EJDataRecord) element;
Object iV = record.getValue(imageid);
if (iV == null) {
return null;
}
Image image = imageMap.get(iV);
if (image != null && !image.isDisposed()) {
return image;
}
if (iV instanceof URL) {
image = ImageDescriptor.createFromURL((URL) iV).createImage();
} else if (iV instanceof byte[]) {
image = new Image(Display.getDefault(), new ByteArrayInputStream((byte[]) iV));
}
if (image != null) {
imageMap.put(iV, image);
}
return image;
}
return super.getImage(element);
}
@Override
public String getText(Object element) {
if (nodeTextProviders.size() == 1) {
return nodeTextProviders.get(0).getText(element);
}
StringBuilder builder = new StringBuilder();
for (TreeNodeTextProvider textProvider : nodeTextProviders) {
builder.append(textProvider.getText(element));
}
return builder.toString();
}
});
int intProperty = rendererProp.getIntProperty(EJRWTTreeBlockDefinitionProperties.NODE_EXPAND_LEVEL, 1);
// workaround
intProperty++;
if (intProperty < 1 && intProperty < 2) {
intProperty = 2;
}
if (intProperty > 1)
_tableViewer.setAutoExpandLevel(intProperty);
_tableViewer.setContentProvider(filteredContentProvider = new FilteredContentProvider() {
private List<EJDataRecord> root = new ArrayList<EJDataRecord>();
private Map<Object, Object> indexMap = new HashMap<Object, Object>();
private Map<Object, List<EJDataRecord>> cmap = new HashMap<Object, List<EJDataRecord>>();
private List<EJDataRecord> froot = new ArrayList<EJDataRecord>();
private Map<Object, List<EJDataRecord>> fcmap = new HashMap<Object, List<EJDataRecord>>();
boolean matchItem(EJDataRecord rec) {
if (filter != null && filter.trim().length() > 0) {
for (TreeNodeTextProvider filterTextProvider : nodeTextProviders) {
String text = filterTextProvider.getText(rec);
if (text != null && text.toLowerCase().contains(filter.toLowerCase())) {
return true;
}
}
}
return false;
}
@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
treeBaseRecords.clear();
if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
froot.clear();
fcmap.clear();
// filter
for (Entry<Object, List<EJDataRecord>> entry : cmap.entrySet()) {
List<EJDataRecord> values = entry.getValue();
List<EJDataRecord> fvalues = new ArrayList<EJDataRecord>(values.size());
fcmap.put(entry.getKey(), fvalues);
for (EJDataRecord record : values) {
if (matchItem(record)) {
fvalues.add(record);
}
}
}
// filter root
for (EJDataRecord record : root) {
if (matchItem(record)) {
froot.add(record);
} else if (hasChildren(record)) {
froot.add(record);
}
}
for (EJDataRecord record : froot) {
treeBaseRecords.add(record);
addSubRecords(record.getValue(pid), fcmap);
}
} else {
filter = null;
if (filterTree != null) {
filterTree.clearText();
}
root.clear();
indexMap.clear();
froot.clear();
cmap.clear();
fcmap.clear();
for (Image img : imageMap.values()) {
img.dispose();
}
imageMap.clear();
Collection<EJDataRecord> records = _block.getRecords();
for (EJDataRecord record : records) {
Object rV = record.getValue(rid);
Object pV = record.getValue(pid);
if (rV == null) {
root.add(record);
if (pid != null) {
indexMap.put(pV, record);
}
continue;
}
List<EJDataRecord> list = cmap.get(rV);
if (list == null) {
list = new ArrayList<EJDataRecord>();
cmap.put(rV, list);
}
list.add(record);
}
// child node with no parent need to consider as roots
MAIN: for (Object key : new HashSet<Object>(cmap.keySet())) {
if (indexMap.containsKey(key)) {
continue;
}
for (EJDataRecord rec : records) {
if (key.equals(rec.getValue(pid))) {
continue MAIN;
}
}
List<EJDataRecord> list = cmap.get(key);
cmap.remove(key);
for (EJDataRecord record : list) {
Object pV = record.getValue(pid);
root.add(record);
if (pid != null) {
indexMap.put(pV, record);
}
}
}
for (EJDataRecord record : root) {
treeBaseRecords.add(record);
addSubRecords(record.getValue(pid), cmap);
}
}
}
private void addSubRecords(Object key, Map<Object, List<EJDataRecord>> cmap) {
if (key != null) {
List<EJDataRecord> list = cmap.get(key);
if (list != null) {
for (EJDataRecord record : list) {
treeBaseRecords.add(record);
addSubRecords(record.getValue(pid), cmap);
}
}
}
}
@Override
public void dispose() {
root.clear();
indexMap.clear();
cmap.clear();
froot.clear();
fcmap.clear();
for (Image img : imageMap.values()) {
img.dispose();
}
imageMap.clear();
}
@Override
public Object[] getElements(Object arg0) {
if (filter != null && filter.trim().length() > 0) {
return froot.toArray();
}
return root.toArray();
}
@Override
public Object[] getChildren(Object arg0) {
Map<Object, List<EJDataRecord>> map = filter != null && filter.trim().length() > 0 ? fcmap : cmap;
if (arg0 instanceof EJDataRecord) {
EJDataRecord record = (EJDataRecord) arg0;
Object pV = record.getValue(pid);
if (pV != null) {
List<EJDataRecord> list = map.get(pV);
if (list != null) {
return list.toArray();
}
}
}
return new Object[0];
}
@Override
public Object getParent(Object arg0) {
if (arg0 instanceof EJDataRecord) {
EJDataRecord record = (EJDataRecord) arg0;
Object rV = record.getValue(rid);
if (rV != null) {
return indexMap.get(rV);
}
}
return null;
}
@Override
public boolean hasChildren(Object arg0) {
if (arg0 instanceof EJDataRecord) {
Map<Object, List<EJDataRecord>> map = filter != null && filter.trim().length() > 0 ? fcmap : cmap;
EJDataRecord record = (EJDataRecord) arg0;
Object pV = record.getValue(pid);
if (pV != null) {
List<EJDataRecord> list = map.get(pV);
return list != null && list.size() > 0;
}
}
return false;
}
});
_tableViewer.setInput(new Object());
selectFirst();
// add double click action
final String doubleClickActionCommand = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.DOUBLE_CLICK_ACTION_COMMAND);
if (doubleClickActionCommand != null) {
_tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent arg0) {
_block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
}
});
}
// add double click action
final String clickActionCommand = rendererProp.getStringProperty(EJRWTTreeBlockDefinitionProperties.CLICK_ACTION_COMMAND);
_tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent arg0) {
EJDataRecord focusedRecord = getFocusedRecord();
if (focusedRecord != null) {
_block.newRecordInstance(focusedRecord);
}
if (clickActionCommand != null) {
_block.executeActionCommand(clickActionCommand, EJScreenType.MAIN);
}
if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.HIDE_SELECTION, false)) {
_tableViewer.removeSelectionChangedListener(this);
_tableViewer.getTree().deselectAll();
_tableViewer.addSelectionChangedListener(this);
}
}
});
}
Aggregations