use of com.twinsoft.convertigo.eclipse.dnd.PaletteSource 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() + "'.");
}
use of com.twinsoft.convertigo.eclipse.dnd.PaletteSource 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.createBean(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