use of com.cubrid.common.ui.query.editor.ColumnProposal in project cubrid-manager by CUBRID.
the class QuickBuilderDialog method createContents.
protected void createContents() {
sqlComp = CommonUITool.getActiveSQLEditorComposite();
if (sqlComp == null) {
closeThisDialog();
return;
}
CubridDatabase cubridDatabase = sqlComp.getQueryEditorPart().getSelectedDatabase();
if (CubridDatabase.hasValidDatabaseInfo(cubridDatabase)) {
databaseInfo = cubridDatabase.getDatabaseInfo();
}
boolean loadedProposal = true;
proposal = ColumnProposalAdvisor.getInstance().findProposal(databaseInfo);
if (proposal == null) {
proposal = new ColumnProposal();
if (databaseInfo != null) {
startTimerForUpdateProposal();
}
loadedProposal = false;
}
isSupportLimit = CompatibleUtil.isSupportLimit(cubridDatabase.getDatabaseInfo());
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
{
GridLayout gl = new GridLayout();
gl.numColumns = 1;
shell.setLayout(gl);
}
shell.setSize(450, 300);
shell.setText(Messages.quickQueryBuilderTitle);
final Composite composite = new Composite(shell, SWT.NONE);
{
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
composite.setLayoutData(gd);
GridLayout gl = new GridLayout();
composite.setLayout(gl);
}
final Label findWhatLabel = new Label(composite, SWT.NONE);
findWhatLabel.setText(Messages.quickQueryBuilderLabel);
inputText = new Text(composite, SWT.BORDER);
{
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
inputText.setLayoutData(gd);
}
inputText.setEditable(true);
inputText.addKeyListener(inputTextKeyListener);
searchView = new TableViewer(composite, SWT.BORDER);
{
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
searchView.getTable().setLayoutData(gd);
}
searchView.setContentProvider(searchViewContentProvider);
searchView.setLabelProvider(searchViewLabelProvider);
searchView.setInput(proposal);
searchView.getTable().addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR) {
makeQueryAndClose(0);
}
}
});
TableColumn col1 = new TableColumn(searchView.getTable(), SWT.NONE);
col1.setWidth(200);
TableColumn col2 = new TableColumn(searchView.getTable(), SWT.NONE);
col2.setWidth(200);
if (!loadedProposal) {
updateNoticeBanner = new Label(composite, SWT.BORDER);
{
GridData gd = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
updateNoticeBanner.setLayoutData(gd);
}
updateNoticeBanner.setText(Messages.quickQueryBuilderLoading);
updateNoticeBanner.setBackground(ResourceManager.getColor(255, 255, 255));
}
Composite bottomPanel = new Composite(composite, SWT.NONE);
{
GridLayout gl = new GridLayout();
gl.numColumns = 4;
bottomPanel.setLayout(gl);
GridData gd = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
bottomPanel.setLayoutData(gd);
}
createButtons(bottomPanel);
}
use of com.cubrid.common.ui.query.editor.ColumnProposal in project cubrid-manager by CUBRID.
the class QuickBuilderDialog method startTimerForUpdateProposal.
private void startTimerForUpdateProposal() {
TimerTask proposalUpdateNotifyTask = new TimerTask() {
public void run() {
ColumnProposal proposalTemp = ColumnProposalAdvisor.getInstance().findProposal(databaseInfo);
if (proposalTemp == null) {
return;
}
if (proposalUpdateTimer != null) {
proposalUpdateTimer.cancel();
proposalUpdateTimer = null;
}
proposal = proposalTemp;
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (updateNoticeBanner != null) {
updateNoticeBanner.dispose();
updateNoticeBanner = null;
}
if (searchView != null) {
searchView.setInput(proposal);
}
shell.layout(true, true);
}
});
}
};
proposalUpdateTimer = new Timer(true);
proposalUpdateTimer.schedule(proposalUpdateNotifyTask, 500);
}
use of com.cubrid.common.ui.query.editor.ColumnProposal in project cubrid-manager by CUBRID.
the class QuickBuilderDialog method makeQueryAndClose.
private void makeQueryAndClose(int type) {
// FIXME move this logic to core module
String tableName = getSelectedTable().trim();
List<ColumnProposalDetailInfo> columns = null;
String query = null;
ColumnProposal proposal = ColumnProposalAdvisor.getInstance().findProposal(sqlComp.getQueryEditorPart().getSelectedDatabase().getDatabaseInfo());
if (proposal != null) {
columns = proposal.getColumns().get(tableName);
}
if (columns == null) {
columns = new ArrayList<ColumnProposalDetailInfo>();
}
int cursorPosition = 0;
if (type == 0) {
query = "SELECT * FROM " + QuerySyntax.escapeKeyword(tableName) + " " + appendLimit() + ";" + StringUtil.NEWLINE;
cursorPosition = query.length() - 1;
} else if (type == 1) {
StringBuilder col = new StringBuilder();
if (columns != null) {
for (ColumnProposalDetailInfo info : columns) {
String column = info.getColumnName();
if (col.length() > 0) {
col.append(", ");
}
col.append(QuerySyntax.escapeKeyword(column));
}
}
query = "SELECT " + col.toString() + " FROM " + QuerySyntax.escapeKeyword(tableName) + " " + appendLimit() + ";" + StringUtil.NEWLINE;
cursorPosition = query.length() - 1;
} else if (type == 2) {
StringBuilder col = new StringBuilder();
StringBuilder col2 = new StringBuilder();
if (columns != null) {
for (ColumnProposalDetailInfo info : columns) {
String column = info.getColumnName();
if (col.length() > 0) {
col.append(", ");
col2.append(", ");
}
col.append(QuerySyntax.escapeKeyword(column));
col2.append(column);
}
}
query = "INSERT INTO " + QuerySyntax.escapeKeyword(tableName) + " (" + col.toString() + ") VALUES (" + col2.toString() + ");\n";
cursorPosition = 14 + tableName.length() + col.length() + 10;
} else if (type == 3) {
StringBuilder col = new StringBuilder();
if (columns != null) {
for (ColumnProposalDetailInfo info : columns) {
String column = info.getColumnName();
if (col.length() > 0) {
col.append(", ");
}
col.append(QuerySyntax.escapeKeyword(column)).append("=");
}
}
query = "UPDATE " + QuerySyntax.escapeKeyword(tableName) + " SET " + col.toString() + " WHERE ;" + StringUtil.NEWLINE;
cursorPosition = 12 + tableName.length();
}
pasteIntoQueryEditor(query, cursorPosition);
closeThisDialog();
}
Aggregations