use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.
the class SessionTreeNodeManager method convert2INode.
/**
* DOC qianbing Comment method "convert2INode". Converts the RepositoryNode input to INode. INode is used for the
* sql editor,result viewer and the detail viewer.
*
* @param repositoryNode RepositoryNode
* @param selectedContext
* @return INode
*/
public INode convert2INode(RepositoryNode repositoryNode, String selectedContext, SessionTreeNode sessionTreeNode) throws Exception {
// Creates the SessionTreeNode.
RepositoryNodeType nodeType = getRepositoryType(repositoryNode);
if (nodeType.equals(RepositoryNodeType.DATABASE)) {
// processes the database
DatabaseModel model = sessionTreeNode.getDbModel();
INode[] nodes = model.getChildNodes();
DatabaseNode dn = (DatabaseNode) nodes[0];
return dn;
} else if (nodeType.equals(RepositoryNodeType.TABLE)) {
// processes the table
MetadataTableRepositoryObject tableObject = (MetadataTableRepositoryObject) repositoryNode.getObject();
MetadataTable table = tableObject.getTable();
String realName = table.getSourceName();
DatabaseModel model = sessionTreeNode.getDbModel();
INode[] nodes = model.getChildNodes();
DatabaseNode dn = (DatabaseNode) nodes[0];
nodes = dn.getChildNodes();
CatalogNode cn = (CatalogNode) nodes[0];
nodes = cn.getChildNodes();
if (nodes != null && nodes.length > 0) {
for (INode node : nodes) {
TableNode tableNode = (TableNode) node;
if (tableNode.getName().equals(realName)) {
return node;
}
}
}
} else if (nodeType.equals(RepositoryNodeType.COLUMN)) {
// Processes the column.
// Gets the repositoryNode's parent,should be the repositoryNode of table infomation.
repositoryNode = repositoryNode.getParent();
return convert2INode(repositoryNode, selectedContext, sessionTreeNode);
}
return null;
}
use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.
the class MetadataColumnComparator method isChangeElementColor.
/**
* dev Comment method "isChangeElementColor".
*
* @param node
* @return
*/
public boolean isChangeElementColor(RepositoryNode node) {
boolean flag = false;
Object type = node.getProperties(EProperties.CONTENT_TYPE);
if (type.equals(RepositoryNodeType.DATABASE)) {
return getItem(node).getConnection().isDivergency();
}
if (type.equals(RepositoryNodeType.TABLE)) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
MetadataTable table = object.getTable();
flag = table.getSourceName().equals(table.getLabel());
flag = flag && table.isDivergency();
}
return flag;
}
use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.
the class MetadataColumnComparator method isDiff.
/**
* dev Comment method "isDiff".
*
* @param node
* @return
*/
@SuppressWarnings("unchecked")
public boolean[] isDiff(RepositoryNode node) {
boolean isDiffDivergency = false;
boolean isDiffSyschronize = false;
boolean isDiffGray = false;
Object type = node.getProperties(EProperties.CONTENT_TYPE);
if (type.equals(RepositoryNodeType.DATABASE)) {
DatabaseConnection connection = (DatabaseConnection) getItem(node).getConnection();
Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
for (MetadataTable table : tables) {
List<MetadataColumn> columns = table.getColumns();
for (MetadataColumn column : columns) {
if (column.isDivergency()) {
isDiffDivergency = true;
}
if (column.isSynchronised()) {
isDiffSyschronize = true;
}
if (column.getLabel() == null || "".equals(column.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
if (table.isDivergency()) {
isDiffDivergency = true;
}
if (table.getLabel() == null || "".equals(table.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
} else if (type.equals(RepositoryNodeType.TABLE)) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
MetadataTable table = object.getTable();
List<MetadataColumn> columns = table.getColumns();
for (MetadataColumn column : columns) {
if (column.isDivergency()) {
isDiffDivergency = true;
}
if (column.isSynchronised()) {
isDiffSyschronize = true;
}
if (column.getLabel() == null || "".equals(column.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
if (table.isDivergency()) {
isDiffDivergency = true;
}
}
return new boolean[] { isDiffGray, isDiffDivergency, isDiffSyschronize };
}
use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.
the class SQLBuilderDialog method okPressed.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
public void okPressed() {
// gain the contextmode from sqlbuilder,and set it in connParameters,add by hyWang
MultiPageSqlBuilderEditor editor = null;
CTabFolder folder = getEditorComposite().getTabFolder();
CTabItem[] a = folder.getItems();
for (CTabItem itm : a) {
//$NON-NLS-1$
Object obj = itm.getData("KEY");
if (obj instanceof MultiPageSqlBuilderEditor) {
editor = (MultiPageSqlBuilderEditor) obj;
}
if (editor != null) {
if (itm.getData() instanceof Query) {
Query q = (Query) itm.getData();
connParameters.setIfContextButtonCheckedFromBuiltIn(q.isContextMode());
}
}
}
if (EParameterFieldType.DBTABLE.equals(connParameters.getFieldType())) {
final IStructuredSelection selection = (IStructuredSelection) structureComposite.getTreeViewer().getSelection();
final Object firstElement = selection.getFirstElement();
if (firstElement instanceof RepositoryNode) {
RepositoryNode node = (RepositoryNode) firstElement;
boolean is = node.getProperties(EProperties.CONTENT_TYPE).equals(RepositoryNodeType.TABLE);
if (is) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
connParameters.setSelectDBTable(object.getSourceName());
}
}
} else {
//$NON-NLS-1$
String sql = "";
// sql = editorComposite.getDefaultTabSql();
sql = editorComposite.getCurrentTabSql();
// if (ConnectionParameters.isJavaProject()) {
// sql = sql.replace("\"", "\\" + "\"");
// } else {
// sql = sql.replace("'", "\\'");
// }
// sql = QueryUtil.checkAndAddQuotes(sql);
connParameters.setQuery(sql);
if (connParameters.isFromRepository() && !connParameters.isNodeReadOnly()) {
List<Query> qs = new ArrayList<Query>();
boolean isInfo = false;
final CTabFolder tabFolder = getEditorComposite().getTabFolder();
final CTabItem[] items = tabFolder.getItems();
for (CTabItem item : items) {
final String text = item.getText();
//$NON-NLS-1$
boolean isInfo2 = text.length() > 1 && text.substring(0, 1).equals("*");
if (isInfo2) {
isInfo = true;
}
}
if (isInfo) {
//$NON-NLS-1$
String title = Messages.getString("SQLBuilderDialog.SaveAllQueries.Title");
//$NON-NLS-1$
String info = Messages.getString("SQLBuilderDialog.SaveAllQueries.Info");
boolean openQuestion = MessageDialog.openQuestion(getShell(), title, info);
if (openQuestion) {
for (CTabItem item : items) {
final String text = item.getText();
//$NON-NLS-1$
boolean isInfo2 = text.length() > 1 && text.substring(0, 1).equals("*");
if (isInfo2) {
MultiPageSqlBuilderEditor meditor = null;
//$NON-NLS-1$
Object control = item.getData("KEY");
if (control instanceof MultiPageSqlBuilderEditor) {
meditor = (MultiPageSqlBuilderEditor) control;
}
if (meditor != null) {
RepositoryNode node = null;
node = meditor.getActivePageRepositoryNode();
if (text.substring(1).startsWith(AbstractSQLEditorComposite.QUERY_PREFIX)) {
if (item.getData() instanceof Query) {
Query q = (Query) item.getData();
q.setValue(meditor.getActivePageSqlString());
// add by hyWang
q.setContextMode(meditor.getActiveEditors().getContextmode().getContextmodeaction().isChecked());
qs.add(q);
if (node != null && q != null) {
manager.saveQuery(node, q, null);
}
}
} else {
meditor.getActivePageSaveAsSQLAction().run();
}
}
}
}
}
}
if (connParameters.getQueryObject() != null) {
RepositoryUpdateManager.updateQuery(connParameters.getQueryObject(), node);
}
}
}
deleteNoUseTable();
super.okPressed();
}
use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject in project tdi-studio-se by Talend.
the class TableNode method getMetadataTable.
/**
* Get repository table from table repositoryNode.
*
* @param repositoryNode -- table repositoryNode
* @return columns
* @exception
*/
//$NON-NLS-1$
@SuppressWarnings("deprecation")
public static MetadataTable getMetadataTable(RepositoryNode repositoryNode) {
RepositoryNodeType type = SQLBuilderRepositoryNodeManager.getRepositoryType(repositoryNode);
if (type != RepositoryNodeType.TABLE) {
//$NON-NLS-1$
throw new RuntimeException(Messages.getString("TableNode.exceptionMessage"));
}
MetadataTableRepositoryObject tableObject = (MetadataTableRepositoryObject) repositoryNode.getObject();
return tableObject.getTable();
}
Aggregations