use of com.twinsoft.convertigo.beans.ngx.components.dynamic.Component in project convertigo by convertigo.
the class ComponentExplorerComposite method findDatabaseObjects.
protected void findDatabaseObjects(String searchText) {
if (objectsMap.isEmpty()) {
try {
List<String> categories = ComponentManager.getGroups();
List<Component> components = ComponentManager.getComponentsByGroup();
handCursor = new Cursor(Display.getDefault(), SWT.CURSOR_HAND);
// initialize composites.
RowLayout rowLayout = new RowLayout();
rowLayout.pack = false;
int i = 0;
Iterator<String> iterator = categories.iterator();
composites = new Composite[categories.size()];
items = new ExpandItem[categories.size()];
while (iterator.hasNext()) {
composites[i] = new Composite(bar, SWT.NONE);
composites[i].setLayout(rowLayout);
composites[i].setBackground(bar.getBackground());
items[i] = new ExpandItem(bar, SWT.NONE, i);
items[i].setControl(composites[i]);
items[i].setExpanded(true);
items[i].setText(iterator.next());
i++;
}
boolean bSelected = true;
for (Component c : components) {
boolean isAllowed = isAllowed(c);
boolean isMatching = searchText.isEmpty() || c.getLabel().toLowerCase().indexOf(searchText.toLowerCase()) != -1 || c.getTag().startsWith(searchText.toLowerCase());
if (isAllowed && isMatching) {
addLabelEx(c, bSelected);
bSelected = false;
}
}
for (ExpandItem expandItem : bar.getItems()) {
Point size = expandItem.getControl().getSize();
if (size.x == 0) {
// case of first time composite view is shown
size = expandItem.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
size.x -= scrolledComposite.getVerticalBar().getSize().x;
}
Point size2 = expandItem.getControl().computeSize(size.x, SWT.DEFAULT);
expandItem.setHeight(size2.y);
}
// We select by default the first item if no default dbo found.
if (currentSelectedObject == null && composites[0].getChildren().length > 0) {
currentSelectedObject = (CLabel) composites[0].getChildren()[0];
}
for (ExpandItem expandItem : bar.getItems()) {
if (((Composite) expandItem.getControl()).getChildren().length == 0) {
expandItem.getControl().dispose();
expandItem.dispose();
}
}
Component currentSelectedComponent = getCurrentSelectedComponent();
if (currentSelectedComponent != null) {
updateHelpText(currentSelectedComponent);
}
if (currentSelectedObject != null && !currentSelectedObject.isDisposed()) {
currentSelectedObject.setForeground(FOREGROUND_SELECTED_COLOR);
currentSelectedObject.setBackground(BACKGROUND_SELECTED_COLOR);
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to load component objects.");
}
}
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.Component in project convertigo by convertigo.
the class ComponentExplorerComposite method addLabelEx.
private void addLabelEx(Component component, boolean bSelected) {
String category = component.getGroup();
if ("".equals(category)) {
composite = composites[0];
} else {
for (int i = 0; i < items.length; i++) {
if (items[i].getText().equals(category)) {
composite = composites[i];
}
}
}
final CLabel label = new CLabel(composite, SWT.NONE);
Image image = null;
try {
image = ConvertigoPlugin.getDefault().getIconFromPath(component.getImagePath(), BeanInfo.ICON_COLOR_32x32);
} catch (Exception e) {
}
label.setImage(image);
label.setText(component.getLabel());
label.setAlignment(SWT.LEFT);
label.setToolTipText(RegexpUtils.removeTag.matcher(getShortDescription(component)).replaceAll(""));
label.setCursor(handCursor);
label.setLayoutData(new RowData());
objectsMap.put(label, component);
if (bSelected) {
currentSelectedObject = label;
}
// DND support for Mobile palette
if (wizardPage == null) {
Transfer[] types = new Transfer[] { PaletteSourceTransfer.getInstance() };
int operations = DND.DROP_COPY | DND.DROP_MOVE;
DragSource source = new DragSource(label, operations);
source.setTransfer(types);
source.addDragListener(new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
try {
if (currentSelectedObject != null && !currentSelectedObject.isDisposed()) {
currentSelectedObject.setForeground(label.getForeground());
currentSelectedObject.setBackground(label.getBackground());
}
currentSelectedObject = label;
currentSelectedObject.setForeground(FOREGROUND_SELECTED_COLOR);
currentSelectedObject.setBackground(BACKGROUND_SELECTED_COLOR);
Component c = (Component) objectsMap.get(label);
DatabaseObject dbo = ComponentManager.createBeanFromHint(c);
if (dbo != null) {
String sXml = ClipboardAction.dnd.copy(dbo);
if (sXml != null) {
event.doit = true;
PaletteSourceTransfer.getInstance().setPaletteSource(new PaletteSource(sXml));
}
} else {
throw new Exception("Invalid database object : null");
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Cannot drag");
}
}
});
}
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
CLabel label = (CLabel) e.getSource();
if (currentSelectedObject == label)
return;
if (currentSelectedObject != null && !currentSelectedObject.isDisposed()) {
currentSelectedObject.setForeground(label.getForeground());
currentSelectedObject.setBackground(label.getBackground());
}
currentSelectedObject = (CLabel) e.getSource();
ConvertigoPlugin.logDebug("currentSelectedObject: '" + currentSelectedObject.getText() + "'.");
currentSelectedObject.setForeground(FOREGROUND_SELECTED_COLOR);
currentSelectedObject.setBackground(BACKGROUND_SELECTED_COLOR);
Component currentSelectedComponent = getCurrentSelectedComponent();
if (currentSelectedComponent != null) {
updateHelpText(currentSelectedComponent);
}
}
@Override
public void mouseDoubleClick(MouseEvent e) {
currentSelectedObject = (CLabel) e.getSource();
if (wizardPage != null) {
wizardPage.setPageComplete(true);
((ComponentExplorerWizardPage) wizardPage).showNextPage();
}
}
});
ConvertigoPlugin.logDebug("Loaded '" + component.getLabel() + "'.");
}
Aggregations