use of org.talend.commons.ui.command.CommandStackForComposite in project tdi-studio-se by Talend.
the class JSONFileStep2Form method addGroupSchemaTarget.
private void addGroupSchemaTarget(final Composite mainComposite, final int width, final int height) {
// Group Schema Viewer
schemaTargetGroup = Form.createGroup(mainComposite, 1, "Target Schema", height);
// to correct graphic bug under Linux-GTK when the wizard is opened the first time
if (WindowSystem.isGTK() && firstTimeWizardOpened.equals(Boolean.TRUE)) {
schemaTargetGroup.addListener(SWT.Paint, new Listener() {
@Override
public void handleEvent(Event event) {
Point offsetPoint = event.display.map(linker.getBgDrawableComposite(), schemaTargetGroup, new Point(0, 0));
linker.setOffset(offsetPoint);
linker.drawBackground(event.gc);
}
});
}
// ///////////////////////////////////////////
schemaTargetGroup.setBackgroundMode(SWT.INHERIT_FORCE);
CommandStackForComposite commandStack = new CommandStackForComposite(schemaTargetGroup);
loopModel = new JSONExtractorLoopModel("Path loop expression");
loopTableEditorView = new ExtractionLoopWithJSONXPathEditorView(loopModel, schemaTargetGroup);
loopTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
GridData data2 = new GridData(GridData.FILL_HORIZONTAL);
data2.heightHint = 90;
final Composite loopTableEditorComposite = loopTableEditorView.getMainComposite();
loopTableEditorComposite.setLayoutData(data2);
loopTableEditorComposite.setBackground(null);
// to correct graphic bug under Linux-GTK when the wizard is opened the first time
if (WindowSystem.isGTK() && firstTimeWizardOpened.equals(Boolean.TRUE)) {
loopTableEditorComposite.addListener(SWT.Paint, new Listener() {
@Override
public void handleEvent(Event event) {
Point offsetPoint = event.display.map(linker.getBgDrawableComposite(), loopTableEditorComposite, new Point(0, 0));
linker.setOffset(offsetPoint);
linker.drawBackground(event.gc);
}
});
}
// ///////////////////////////////////////////
// Messages.getString("FileStep3.metadataDescription")
fieldsModel = new JSONExtractorFieldModel("Fields to extract");
fieldsTableEditorView = new ExtractionFieldsWithJSONXPathEditorView(fieldsModel, schemaTargetGroup);
fieldsTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
final Composite fieldTableEditorComposite = fieldsTableEditorView.getMainComposite();
data2 = new GridData(GridData.FILL_BOTH);
data2.heightHint = 180;
fieldTableEditorComposite.setLayoutData(data2);
fieldTableEditorComposite.setBackground(null);
// to correct graphic bug under Linux-GTK when the wizard is opened the first time
if (WindowSystem.isGTK() && firstTimeWizardOpened.equals(Boolean.TRUE)) {
fieldTableEditorComposite.addListener(SWT.Paint, new Listener() {
@Override
public void handleEvent(Event event) {
Point offsetPoint = event.display.map(linker.getBgDrawableComposite(), fieldTableEditorComposite, new Point(0, 0));
linker.setOffset(offsetPoint);
linker.drawBackground(event.gc);
}
});
}
// ///////////////////////////////////////////
}
use of org.talend.commons.ui.command.CommandStackForComposite in project tdi-studio-se by Talend.
the class JSONFileStep2Form method resetStatusIfNecessary.
/**
* see bug 0004206: bug on the loop limit case in JSONfile source metadata defining
*/
private void resetStatusIfNecessary() {
String curJSONPath = getConnection().getJSONFilePath();
//$NON-NLS-1$
String oraginalPath = "";
if (jsonFilePath != null && curJSONPath != null) {
// change JSON file
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
oraginalPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, curJSONPath));
}
if ((!jsonFilePath.equals(curJSONPath) && !jsonFilePath.equals(oraginalPath)) || !this.wizard.getReadbyMode().equals(currentReadbyMode)) {
currentReadbyMode = this.wizard.getReadbyMode();
// clear command stack
CommandStackForComposite commandStack = new CommandStackForComposite(schemaTargetGroup);
loopTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
fieldsTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
getConnection().getSchema().remove(jsonXPathLoopDescriptor);
jsonXPathLoopDescriptor = JsonFactory.eINSTANCE.createJSONXPathLoopDescriptor();
getConnection().getSchema().add(jsonXPathLoopDescriptor);
loopModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor);
XmlArray.setLimitToDefault();
jsonXPathLoopDescriptor.setLimitBoucle(XmlArray.getRowLimit());
fieldsModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor.getSchemaTargets());
fieldsTableEditorView.getTableViewerCreator().layout();
initTreePopulator();
prepareJsonLinker();
// reset linker
linker.init(treePopulator);
loopTableEditorView.setLinker(linker);
fieldsTableEditorView.setLinker(linker);
jsonFilePreview.removePreviewContent();
}
}
if (isContextMode()) {
jsonFilePath = oraginalPath;
} else {
jsonFilePath = curJSONPath;
}
}
use of org.talend.commons.ui.command.CommandStackForComposite in project tdi-studio-se by Talend.
the class MultiSchemasUI method addButtonListeners.
protected void addButtonListeners() {
// Event PreviewButton
previewBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
refreshPreview();
}
});
fetchBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
fetchCodes();
}
});
leftBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
getUIManager().moveRecord(schemaTreeViewer, true);
getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
});
rightBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
getUIManager().moveRecord(schemaTreeViewer, false);
getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
});
addRow.addSelectionListener(new // hywang for 10263
SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SchemasKeyData root = (SchemasKeyData) schemaTreeViewer.getInput();
AddRowDialog dialog = new AddRowDialog(MultiSchemasUI.this.getShell(), root);
if (Window.OK == dialog.open()) {
Object input = schemaTreeViewer.getInput();
if (input instanceof SchemasKeyData) {
SchemasKeyData data = (SchemasKeyData) input;
List<SchemasKeyData> all = data.getChildren();
SchemasKeyData newData = new SchemasKeyData(dialog.getRecordValue());
newData.setSeparator(dialog.getSepValue());
newData.setUniqueRecord(dialog.getKeyValue());
final IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), dialog.getKeyValue());
if (metadataTable != null) {
multiSchemaManager.createMultiSchemasColumns(newData, metadataTable.clone(true));
} else {
List<MultiMetadataColumn> colums = multiSchemaManager.createPropertiesColumns(newData);
newData.setMetadataColumns(colums);
}
all.add(newData);
data.addChild(newData);
newData.setParent(data);
schemaTreeViewer.refresh();
int len = schemaTreeViewer.getTree().getItems().length;
schemaTreeViewer.getTree().select(schemaTreeViewer.getTree().getItems()[len - 1]);
}
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
}
});
removeRow.addSelectionListener(new // hywang for 10263
SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean needRefresh = false;
if (schemaTreeViewer == null) {
return;
}
SchemasKeyData removeData = null;
ISelection selection = schemaTreeViewer.getSelection();
Object input = schemaTreeViewer.getInput();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof SchemasKeyData) {
removeData = (SchemasKeyData) element;
}
}
if (input instanceof SchemasKeyData) {
SchemasKeyData data = (SchemasKeyData) input;
List<SchemasKeyData> all = data.getChildren();
if (all.contains(removeData)) {
all.remove(removeData);
schemaTreeViewer.setInput(data);
needRefresh = true;
}
if (needRefresh) {
schemaTreeViewer.refresh();
int len = schemaTreeViewer.getTree().getItems().length;
if (len > 0) {
schemaTreeViewer.getTree().select(schemaTreeViewer.getTree().getItems()[len - 1]);
}
removeRow.setEnabled(!all.isEmpty());
editSchema.setEnabled(!all.isEmpty());
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
}
}
});
editSchema.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = schemaTreeViewer.getSelection();
SchemasKeyData selectedData = null;
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof SchemasKeyData) {
selectedData = (SchemasKeyData) element;
IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), selectedData.getUniqueRecord());
if (metadataTable == null) {
metadataTable = new org.talend.core.model.metadata.MetadataTable();
}
metadataTable.getListColumns().clear();
SchemasKeyData keydata = (SchemasKeyData) schemaTreeViewer.getInput();
for (int i = 0; i < keydata.getChildren().size(); i++) {
if (selectedData.getUniqueRecord().equals(keydata.getChildren().get(i).getUniqueRecord())) {
metadataTable.getListColumns().addAll(keydata.getChildren().get(i).getMetadataColumns());
break;
}
}
MetadataDialog dialog = new MetadataDialog(MultiSchemasUI.this.getShell(), metadataTable, getMultiSchemasComponent(), new CommandStackForComposite(MultiSchemasUI.this.getShell()));
dialog.setText("Schema of " + selectedData.getUniqueRecord());
if (Window.OK == dialog.open()) {
metadataTable = dialog.getOutputMetaData();
if (!selectedData.getMetadataColumns().isEmpty()) {
selectedData.getMetadataColumns().clear();
}
multiSchemaManager.createMultiSchemasColumns(selectedData, metadataTable);
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
}
}
}
});
}
Aggregations