use of net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary in project tdq-studio-se by Talend.
the class MetaDataSession method initialise.
/**
* Initialises the metadata, but only if the meta data has not already been collected
*/
private void initialise() throws SQLException {
if (getConnection() != null)
return;
_assistanceEnabled = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.SQL_ASSIST);
if (_assistanceEnabled) {
// schedule job to load dictionary for this session
dictionary = new Dictionary();
DictionaryLoader dictionaryLoader = new DictionaryLoader(this);
dictionaryLoader.schedule(500);
}
SQLConnection connection = null;
try {
connection = grabConnection();
metaData = connection.getSQLMetaData();
// MOD gdbu 2011-4-12 bug : 20578
databaseProductName = metaData.getDatabaseProductName();
dbModel = new DatabaseModel(this);
if (metaData.supportsCatalogs())
catalogs = metaData.getCatalogs();
} catch (SQLException sqlerror) {
SQLExplorerPlugin.error(sqlerror);
// ~20578
} finally {
if (connection != null)
releaseConnection(connection);
}
}
use of net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary in project tdq-studio-se by Talend.
the class SQLTextEditor method createSourceViewer.
@Override
protected ISourceViewer createSourceViewer(final Composite parent, IVerticalRuler ruler, int style) {
parent.setLayout(new FillLayout());
final Composite myParent = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0;
myParent.setLayout(layout);
// create divider line
Composite div1 = new Composite(myParent, SWT.NONE);
GridData lgid = new GridData();
lgid.grabExcessHorizontalSpace = true;
lgid.horizontalAlignment = GridData.FILL;
lgid.heightHint = 1;
lgid.verticalIndent = 1;
div1.setLayoutData(lgid);
div1.setBackground(editor.getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
// create text viewer
GridData gid = new GridData();
gid.grabExcessHorizontalSpace = gid.grabExcessVerticalSpace = true;
gid.horizontalAlignment = gid.verticalAlignment = GridData.FILL;
Dictionary dictionary = null;
if (editor.getSession() != null && _enableContentAssist) {
dictionary = editor.getSession().getUser().getMetaDataSession().getDictionary();
}
sqlTextViewer = new SQLTextViewer(myParent, style, store, dictionary, ruler);
sqlTextViewer.getControl().setLayoutData(gid);
// create bottom divider line
Composite div2 = new Composite(myParent, SWT.NONE);
lgid = new GridData();
lgid.grabExcessHorizontalSpace = true;
lgid.horizontalAlignment = GridData.FILL;
lgid.heightHint = 1;
lgid.verticalIndent = 0;
div2.setLayoutData(lgid);
div2.setBackground(editor.getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
final SQLEditor thisEditor = editor;
sqlTextViewer.getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {
private ExecSQLAction _execSQLAction = new ExecSQLAction(thisEditor);
@Override
public void verifyKey(VerifyEvent event) {
if (event.stateMask == SWT.CTRL && event.keyCode == 13) {
event.doit = false;
_execSQLAction.run();
}
}
});
sqlTextViewer.getTextWidget().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
SQLTextEditor.this.editor.getEditorSite().getPage().activate(SQLTextEditor.this.editor.getEditorSite().getPart());
}
});
myParent.layout();
IDocument dc = new Document();
sqlTextViewer.setDocument(dc);
mcl.install(sqlTextViewer);
return sqlTextViewer;
}
use of net.sourceforge.sqlexplorer.sessiontree.model.utility.Dictionary in project tdq-studio-se by Talend.
the class MouseClickListener method getCurrentTextRegion.
private IRegion getCurrentTextRegion(ISourceViewer viewer) {
if (viewer == null)
return null;
Dictionary dictionary = ((SQLTextViewer) viewer).dictionary;
if (dictionary == null)
return null;
int offset = getCurrentTextOffset(viewer);
if (offset == -1)
return null;
try {
IRegion reg = selectWord(viewer.getDocument(), offset);
if (reg == null)
return null;
String selection = viewer.getDocument().get(reg.getOffset(), reg.getLength());
if (selection == null)
return null;
Object obj = dictionary.getByTableName(selection.toLowerCase());
if (obj == null)
return null;
else {
if (!(obj instanceof ArrayList))
return null;
ArrayList ls = (ArrayList) obj;
if (ls.isEmpty())
return null;
Object node = ((ArrayList) obj).get(0);
if (node instanceof TableNode)
activeTableNode = (INode) node;
else
return null;
}
return reg;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations