/** * {@inheritDoc} * * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object) */ @Override public String getText(Object element) { String result = PluginConstants.EMPTY_STRING; Binding binding = (Binding) element; switch (this.columnNumber) { // | status icon | Source SQL Symbol | <-- | Matched Datatype | -> | Target Column case 0: break; case 1: result = binding.getSqlSymbolText(true); break; case 2: break; case 3: Object attr = binding.getAttribute(); // Attribute Datatype Label EObject datatype = null; attr = binding.getAttribute(); if (TransformationHelper.isSqlColumn(attr)) { datatype = bindingListInput.getTargetDatatype(binding); } result = getDatatypeText(datatype); break; case 4: break; case 5: result = binding.getAttributeText(true); break; default: break; } return result; }
@Override protected void setElementValue(Object element, Object newValue) { if (element instanceof Binding && newValue instanceof Boolean) { Binding binding = (Binding) element; Object attr = binding.getAttribute(); if (TransformationHelper.isSqlColumn(attr)) { Shell shell = UiPlugin.getDefault().getCurrentWorkbenchWindow().getShell(); DatatypeSelectionDialog dialog = new DatatypeSelectionDialog(shell, (EObject) attr, "string"); // $NON-NLS-1$ Object originalValue = bindingListInput.getTargetDatatype(binding); Object[] selection = new Object[] {originalValue}; selection[0] = originalValue; dialog.setInitialSelections(selection); int status = dialog.open(); EObject newDatatype = (EObject) originalValue; if (status == Window.OK) { Object[] result = dialog.getResult(); if (result.length == 0) { // null out the value newDatatype = null; } else { // return the selected value newDatatype = (EObject) result[0]; } } // If different datatype was chosen, set it on the binding if (newDatatype != null && !newDatatype.equals(originalValue)) { bindingListInput.setTargetDatatype(binding, newDatatype); updateAttributeConversionPanelButtons(binding); } } // chooserPanel.layout(); bindingTableViewer.refresh(true); updateRowColors(); updateMessageArea(); } }
/* (non-Javadoc) * @See org.teiid.designer.ui.actions.IModelObjectEditHelper#canDelete(java.lang.Object) */ @Override public boolean canDelete(Object obj) { if (obj instanceof EObject) { // Defect 23466 - Need to put a hack in here to NOT allow deleting if the focused part is // Diagram Editor, the diagram is // a transformation & the transformation global actions manager says it can or not. // This is because the SQL Editor global actions may supercede the DiagramEditor's and there // is no framework to restore // these actions at the momement. // Let's Check out the selection's source. If it's IWorkbenchPart activePart = UiPlugin.getDefault().getCurrentWorkbenchWindow().getPartService().getActivePart(); if (activePart instanceof ModelEditor) { IEditorPart activeSubEditorPart = ((ModelEditor) activePart).getActiveEditor(); if (activeSubEditorPart instanceof DiagramEditor) { DiagramViewer viewer = ((DiagramEditor) activeSubEditorPart).getDiagramViewer(); if (viewer.isValidViewer() && viewer.hasFocus()) { // Check for T-Diagram Diagram diagram = viewer.getEditor().getDiagram(); if (diagram.getType().equals(PluginConstants.MAPPING_TRANSFORMATION_DIAGRAM_TYPE_ID)) { EObject vTable = diagram.getTarget(); if (vTable != null) { EObject transform = TransformationHelper.getTransformationMappingRoot(vTable); if (transform != null) { IStructuredSelection diagramSelection = (IStructuredSelection) viewer.getSelection(); List selectedObjs = SelectionUtilities.getSelectedEObjects(diagramSelection); if (selectedObjs.contains(obj)) { return TransformationGlobalActionsManager.canDelete(transform, selectedObjs); } } } } } } } } return true; }
/** handler for Datatype chooser dialog */ void showDatatypeDialogPressed() { Binding binding = getSelectedBinding(); if (binding != null) { Object attr = binding.getAttribute(); if (TransformationHelper.isSqlColumn(attr)) { Shell shell = UiPlugin.getDefault().getCurrentWorkbenchWindow().getShell(); DatatypeSelectionDialog dialog = new DatatypeSelectionDialog(shell, (EObject) attr, "string"); // $NON-NLS-1$ Object originalValue = this.chooserDatatype; Object[] selection = new Object[] {originalValue}; selection[0] = originalValue; dialog.setInitialSelections(selection); int status = dialog.open(); EObject newDatatype = (EObject) originalValue; if (status == Window.OK) { Object[] result = dialog.getResult(); if (result.length == 0) { // null out the value newDatatype = null; } else { // return the selected value newDatatype = (EObject) result[0]; } } // If different datatype was chosen, set it on the binding if (!newDatatype.equals(originalValue)) { setChooserDatatype(newDatatype); updateAttributeConversionPanelButtons(binding); } } attrGroup.layout(); // chooserPanel.layout(); tableViewer.refresh(true); updateRowColors(); updateMessageArea(); } }
private Collection getTransforMationsForTable( final Object container, final String entityName, final char recordType, final boolean isPartialName) { AbstractNameFinder finder = null; switch (recordType) { case IndexConstants.RECORD_TYPE.SELECT_TRANSFORM: case IndexConstants.RECORD_TYPE.INSERT_TRANSFORM: case IndexConstants.RECORD_TYPE.UPDATE_TRANSFORM: case IndexConstants.RECORD_TYPE.DELETE_TRANSFORM: case IndexConstants.RECORD_TYPE.MAPPING_TRANSFORM: finder = new TableNameFinder(entityName, isPartialName); break; case IndexConstants.RECORD_TYPE.PROC_TRANSFORM: finder = new ProcedureNameFinder(entityName, isPartialName); break; default: throw new ModelerCoreRuntimeException( TransformationPlugin.Util.getString( "TransformationMetadata.No_known_index_file_type_associated_with_the_recordType_1", new Character(recordType))); // $NON-NLS-1$ } executeVisitor(container, finder, ModelVisitorProcessor.DEPTH_INFINITE); Collection matches = finder.getMatchingEObjects(); Collection transforms = new ArrayList(matches.size()); for (Iterator targetIter = matches.iterator(); targetIter.hasNext(); ) { EObject targetObj = (EObject) targetIter.next(); if (org.teiid.designer.core.metamodel.aspect.sql.SqlAspectHelper.isValidTransformationTarget( targetObj)) { EObject mappinRoot = TransformationHelper.getMappingRoot(targetObj); transforms.add(mappinRoot); } } return transforms; }
private void createResolveAttributePanel(Composite parent) { if (this.targetLocked) { attrGroup = WidgetFactory.createGroup(parent, RESOLVE_ATTR_GROUP_LOCKED_NAME); } else { attrGroup = WidgetFactory.createGroup(parent, RESOLVE_ATTR_GROUP_NAME); } GridLayout gridLayout = new GridLayout(); attrGroup.setLayout(gridLayout); gridLayout.numColumns = 4; gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; gridLayout.marginLeft = 5; gridLayout.marginBottom = 5; GridData gridData = new GridData(GridData.FILL_HORIZONTAL); attrGroup.setLayoutData(gridData); Binding binding = bindingList.get(0); Object attr = binding.getAttribute(); // Attribute Datatype Label EObject datatype = null; attr = binding.getAttribute(); if (TransformationHelper.isSqlColumn(attr)) { datatype = TransformationHelper.getSqlColumnDatatype((EObject) attr); } String datatypeText = getDatatypeText(datatype); Image datatypeImage = getDatatypeImage(datatype); attrGroup.setText(VIRTUAL_TARGET_ATTRIBUTE_TXT); // -------------------------------------- // SQL Symbol Label // -------------------------------------- attributeLabel = WidgetFactory.createLabel(attrGroup, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // $NON-NLS-1$ GridData attrGD = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_FILL, false, false, 4, 1); attributeLabel.setLayoutData(attrGD); attributeLabel.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLUE)); Label rtTypeLabel = WidgetFactory.createLabel(attrGroup, RUNTIME_TYPE_TXT); GridData gdRT = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, false, false, 2, 1); rtTypeLabel.setLayoutData(gdRT); WidgetFactory.createLabel(attrGroup, CoreStringUtil.Constants.EMPTY_STRING); // -------------------------------------- // Attribute RuntimeType Label // -------------------------------------- attrRuntimeTypeLabel = WidgetFactory.createLabel( attrGroup, datatypeText, datatypeImage, GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.GRAB_HORIZONTAL); // -------------------------------------- // Attribute Type Chooser Panel // -------------------------------------- // Create the changeSelectedAttribute Button this.convertSelectedAttrButton = WidgetFactory.createButton( attrGroup, CONVERT_SELECTED_ATTR_BUTTON, GridData.HORIZONTAL_ALIGN_BEGINNING); this.convertSelectedAttrButton.setEnabled(false); this.convertSelectedAttrButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { convertSelectedAttrPressed(); } }); // Create the changeAllAttributes Button this.convertAllAttrsButton = WidgetFactory.createButton( attrGroup, CONVERT_ALL_ATTR_BUTTON, GridData.HORIZONTAL_ALIGN_BEGINNING); this.convertAllAttrsButton.setEnabled(false); this.convertAllAttrsButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { convertAllAttrsPressed(); } }); // Create the showDatatypeDialog Button this.showDatatypeDialogButton = WidgetFactory.createButton( attrGroup, "Change", GridData.HORIZONTAL_ALIGN_END); // $NON-NLS-1$ this.showDatatypeDialogButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { showDatatypeDialogPressed(); } }); attrDatatypeLabel = WidgetFactory.createLabel( attrGroup, "xxxxxxxxxxxxxxxxxxxxxxx", datatypeImage, //$NON-NLS-1$ GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.GRAB_HORIZONTAL); if (this.targetLocked) { this.showDatatypeDialogButton.setEnabled(false); } else { this.showDatatypeDialogButton.setEnabled(true); } }
public String getSqlOutputString(ModelResource modelResource) throws ModelWorkspaceException { List transformations = modelResource.getModelTransformations().getTransformations(); int nTransforms = transformations.size(); int initBufferSize = nTransforms * 200; StringBuffer sb = new StringBuffer(initBufferSize); String relativeTablePath = null; boolean hasMissingSelects = false; boolean hasMissingInserts = false; boolean hasMissingUpdates = false; boolean hasMissingDeletes = false; for (Iterator iter = transformations.iterator(); iter.hasNext(); ) { Object obj = iter.next(); String rowString = null; if (obj instanceof SqlTransformationMappingRoot) { EObject table = ((SqlTransformationMappingRoot) obj).getTarget(); relativeTablePath = ModelerCore.getModelEditor().getModelRelativePath(table).toString(); String userString = TransformationHelper.getSelectSqlString(obj); if (userString != null && relativeTablePath != null) { rowString = createRowForFile(QueryValidator.SELECT_TRNS, relativeTablePath, userString); if (rowString != null && rowString.length() > 0) { sb.append(rowString); } } else { hasMissingSelects = true; } // Now check if updates allowed boolean tableSupportsUpdates = TransformationHelper.tableSupportsUpdate(table); if (tableSupportsUpdates) { if (TransformationHelper.supportsInsert((EObject) obj, null)) { userString = TransformationHelper.getInsertSqlString(obj); if (userString != null && relativeTablePath != null) { rowString = createRowForFile(QueryValidator.INSERT_TRNS, relativeTablePath, userString); if (rowString != null && rowString.length() > 0) { sb.append(rowString); } } else { hasMissingInserts = true; } } if (TransformationHelper.supportsUpdate((EObject) obj, null)) { userString = TransformationHelper.getUpdateSqlString(obj); if (userString != null && relativeTablePath != null) { rowString = createRowForFile(QueryValidator.UPDATE_TRNS, relativeTablePath, userString); if (rowString != null && rowString.length() > 0) { sb.append(rowString); } } else { hasMissingUpdates = true; } } if (TransformationHelper.supportsDelete((EObject) obj, null)) { userString = TransformationHelper.getDeleteSqlString(obj); if (userString != null && relativeTablePath != null) { rowString = createRowForFile(QueryValidator.DELETE_TRNS, relativeTablePath, userString); if (rowString != null && rowString.length() > 0) { sb.append(rowString); } } else { hasMissingDeletes = true; } } } } } // If operations are missing, specify in the error message if (hasMissingSelects || hasMissingInserts || hasMissingUpdates || hasMissingDeletes) { int count = 0; StringBuffer msgBuff = new StringBuffer( UiConstants.Util.getString( "ExportTransformationSqlToTextAction.exportQueryProblem", modelResource.getItemName())); // $NON-NLS-1$ msgBuff.append(SPACE + LEFT_BRACKET); if (hasMissingSelects) { msgBuff.append(ISQLConstants.SQL_TYPE_SELECT_STRING); count++; } if (hasMissingInserts) { if (count > 0) msgBuff.append(SPACE + DELIMETER + SPACE); msgBuff.append(ISQLConstants.SQL_TYPE_INSERT_STRING); count++; } if (hasMissingUpdates) { if (count > 0) msgBuff.append(SPACE + DELIMETER + SPACE); msgBuff.append(ISQLConstants.SQL_TYPE_UPDATE_STRING); count++; } if (hasMissingDeletes) { if (count > 0) msgBuff.append(SPACE + DELIMETER + SPACE); msgBuff.append(ISQLConstants.SQL_TYPE_DELETE_STRING); count++; } msgBuff.append(RIGHT_BRACKET); UiConstants.Util.log(IStatus.ERROR, msgBuff.toString()); } return sb.toString(); }