use of org.talend.designer.scd.util.DragDropManager in project tdi-studio-se by Talend.
the class SurrogateSection method createContents.
@Override
protected void createContents(Composite parent) {
dragDropManager = new DragDropManager();
key = new SurrogateKey();
final Color white = parent.getDisplay().getSystemColor(SWT.COLOR_WHITE);
parent.setBackground(white);
Composite composite = new Composite(parent, SWT.NONE);
composite.setBackground(white);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.CENTER, SWT.CENTER).applyTo(composite);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
// row 1
Label nameLabel = new Label(composite, SWT.NONE);
//$NON-NLS-1$
nameLabel.setText("name");
nameLabel.setBackground(white);
GridDataFactory.swtDefaults().applyTo(nameLabel);
nameText = new Text(composite, SWT.BORDER);
GridDataFactory.swtDefaults().hint(SURROGATE_FIELD_WIDTH, SWT.DEFAULT).applyTo(nameText);
nameText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (StringUtils.isEmpty(nameText.getText())) {
nameText.setBackground(ERROR_COLOR);
} else {
nameText.setBackground(white);
}
// update model value
key.setColumn(nameText.getText());
}
});
// row 2
Label creationLabel = new Label(composite, SWT.NONE);
//$NON-NLS-1$
creationLabel.setText("creation");
creationLabel.setBackground(white);
GridDataFactory.swtDefaults().applyTo(creationLabel);
creationCombo = new CCombo(composite, SWT.READ_ONLY | SWT.BORDER);
creationCombo.setItems(getScdManager().getSurrogateCreationTypeNames());
GridDataFactory.swtDefaults().hint(SURROGATE_FIELD_WIDTH + 3, SWT.DEFAULT).applyTo(creationCombo);
// row 3
Label complementLabel = new Label(composite, SWT.NONE);
//$NON-NLS-1$
complementLabel.setText("complement");
complementLabel.setBackground(white);
GridDataFactory.swtDefaults().applyTo(complementLabel);
final Composite complementComp = new Composite(composite, SWT.NONE);
GridDataFactory.swtDefaults().applyTo(complementComp);
final StackLayout stack = new StackLayout();
complementComp.setLayout(stack);
final Composite inputFieldComp = new Composite(complementComp, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(inputFieldComp);
inputFieldLabel = new Label(inputFieldComp, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, true).hint(100, SWT.DEFAULT).applyTo(inputFieldLabel);
// add drag and drop support for input field
IDragDropDelegate delegate = createDragDropDelegate(inputFieldLabel);
dragDropManager.addDragSupport(inputFieldLabel, delegate);
dragDropManager.addDropSupport(inputFieldLabel, delegate);
// show DB_SEQUENCE in OraleSCD
// final boolean enableOracle = getScdManager().enableOracle();
// if (enableOracle) {
dbSequenceComp = new Composite(complementComp, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(dbSequenceComp);
dbSequenceText = new Text(dbSequenceComp, SWT.BORDER);
dbSequenceText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (StringUtils.isEmpty(dbSequenceText.getText())) {
dbSequenceText.setBackground(ERROR_COLOR);
} else {
dbSequenceText.setBackground(white);
}
if (key.getCreation() == SurrogateCreationType.DB_SEQUENCE) {
key.setComplement(dbSequenceText.getText());
}
}
});
GridDataFactory.fillDefaults().hint(SURROGATE_FIELD_WIDTH, SWT.DEFAULT).applyTo(dbSequenceText);
TalendProposalUtils.installOn(dbSequenceText, null);
// }
final Composite routineFieldComp = new Composite(complementComp, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(routineFieldComp);
routineText = new Text(routineFieldComp, SWT.BORDER);
routineText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (StringUtils.isEmpty(routineText.getText())) {
routineText.setBackground(ERROR_COLOR);
} else {
routineText.setBackground(white);
}
if (key.getCreation() == SurrogateCreationType.ROUTINE) {
// update model value
key.setComplement(routineText.getText());
}
}
});
GridDataFactory.fillDefaults().hint(SURROGATE_FIELD_WIDTH, SWT.DEFAULT).applyTo(routineText);
// add content proposal for routine
TalendProposalUtils.installOn(routineText, null);
final Label emptyLabel = new Label(complementComp, SWT.NONE);
emptyLabel.setBackground(white);
stack.topControl = emptyLabel;
// when combo is changed, also change the control in complement
creationSwitch = new Runnable() {
public void run() {
String diaplayName = creationCombo.getText();
// SurrogateCreationType type = SurrogateCreationType.getTypeByIndex(index + 1);
SurrogateCreationType type = SurrogateCreationType.getTypeByName(diaplayName);
key.setCreation(type);
if (type == SurrogateCreationType.ROUTINE) {
// routineText;
stack.topControl = routineFieldComp;
if (StringUtils.isEmpty(routineText.getText())) {
routineText.setBackground(ERROR_COLOR);
//$NON-NLS-1$
key.setComplement("");
} else {
routineText.setBackground(white);
}
//$NON-NLS-1$
inputFieldLabel.setText("");
// if (enableOracle) {
//$NON-NLS-1$
dbSequenceText.setText("");
// }
} else if (type == SurrogateCreationType.INPUT_FIELD) {
// inputFieldLabel;
stack.topControl = inputFieldComp;
if (StringUtils.isEmpty(inputFieldLabel.getText())) {
inputFieldLabel.setBackground(ERROR_COLOR);
//$NON-NLS-1$
key.setComplement("");
} else {
inputFieldLabel.setBackground(null);
}
//$NON-NLS-1$
routineText.setText("");
// if (enableOracle) {
//$NON-NLS-1$
dbSequenceText.setText("");
// }
} else if (type == SurrogateCreationType.DB_SEQUENCE) {
// else if (type == SurrogateCreationType.DB_SEQUENCE && enableOracle) {
// dbSequenceText;
stack.topControl = dbSequenceComp;
if (StringUtils.isEmpty(dbSequenceText.getText())) {
dbSequenceText.setBackground(ERROR_COLOR);
//$NON-NLS-1$
key.setComplement("");
} else {
dbSequenceText.setBackground(white);
}
//$NON-NLS-1$
inputFieldLabel.setText("");
routineText.setText("");
} else {
stack.topControl = emptyLabel;
//$NON-NLS-1$
routineText.setText("");
//$NON-NLS-1$
inputFieldLabel.setText("");
// if (enableOracle) {
//$NON-NLS-1$
dbSequenceText.setText("");
// }
//$NON-NLS-1$
key.setComplement("");
}
scdManager.fireFieldChange();
complementComp.layout();
}
};
creationCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
creationSwitch.run();
}
});
}
Aggregations