use of com.cubrid.common.ui.query.dialog.ExportResultDialog in project cubrid-manager by CUBRID.
the class QueryExecuter method createContextMenuItems.
private void createContextMenuItems() {
Menu menu = new Menu(queryEditor.getEditorSite().getShell(), SWT.POP_UP);
final MenuItem itemInsert = new MenuItem(menu, SWT.PUSH);
itemInsert.setText(Messages.insertRecord);
itemInsert.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (!getEditable()) {
CommonUITool.openErrorBox(Display.getDefault().getActiveShell(), Messages.errNotEditable);
return;
}
insertSaveItem.setEnabled(getEditable());
rollbackModifiedItem.setEnabled(getEditable());
addNewItem();
}
});
final MenuItem itemCopy = new MenuItem(menu, SWT.PUSH);
itemCopy.setText(Messages.copyClipBoard);
final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
itemDelete.setText(Messages.delete);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemDetail = new MenuItem(menu, SWT.PUSH);
itemDetail.setText(Messages.detailView);
itemDetail.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
List<Point> selectedList = selectableSupport.getSelectedLocations();
Point location = selectedList.get(0);
if (location == null) {
CommonUITool.openErrorBox(Messages.errShowDetailFailed);
return;
}
//Bug fixed by Kevin.Qian. FYI. allDataList is a global query result to the current query.
int pageBeginIndex = (queryInfo.getCurrentPage() - 1) * queryInfo.getPageSize();
Map<String, CellValue> map = allDataList.get(pageBeginIndex + location.y);
TableItem item = tblResult.getItem(location.y);
ColumnInfo colInfo = allColumnList.get(location.x - 1);
RowDetailDialog dialog = new RowDetailDialog(tblResult.getShell(), allColumnList, map, item, colInfo.getName(), executer);
dialog.open();
}
});
tblResult.setMenu(menu);
tblResult.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
// Point pt = new Point(event.x, event.y);
// itemOid.setEnabled(false);
int index = tblResult.getSelectionIndex();
int count = tblResult.getItemCount();
if (index < 0 || index >= count) {
return;
}
// final TableItem item = tblResult.getItem(index);
// for (int i = 0; i < tblResult.getColumnCount(); i++) {
// Rectangle rect = item.getBounds(i);
// if (rect.contains(pt)) {
// selColumnName = tblResult.getColumn(i).getText();
//// Object value = item.getData(i + "");
//// String text = item.getText(i);
//// if (!DataType.VALUE_NULL.equals(value) && containsOIDs(tblResult.getColumn(i).getText())
//// && !DataType.VALUE_NONE.equals(text)) {
//// itemOid.setEnabled(true);
//// } else {
//// itemOid.setEnabled(false);
//// }
//
// }
// }
}
});
final MenuItem itemExportAll = new MenuItem(menu, SWT.PUSH);
itemExportAll.setText(Messages.allExport);
final MenuItem itemExportSelection = new MenuItem(menu, SWT.PUSH);
itemExportSelection.setText(Messages.selectExport);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemMakeInsertQuery = new MenuItem(menu, SWT.PUSH);
itemMakeInsertQuery.setText(Messages.makeInsertFromSelectedRecord);
itemMakeInsertQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_insert.png"));
final MenuItem itemMakeUpdateQuery = new MenuItem(menu, SWT.PUSH);
itemMakeUpdateQuery.setText(Messages.makeUpdateFromSelectedRecord);
itemMakeUpdateQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_update.png"));
if (isEmpty()) {
itemExportAll.setEnabled(false);
itemExportSelection.setEnabled(false);
itemDetail.setEnabled(false);
}
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
List<Point> selectedList = selectableSupport.getSelectedLocations();
TableItem[] tblItems = selectableSupport.getSelectedTableItems();
boolean selectedCol = selectableSupport.hasSelected();
boolean enableItemDetail = (selectedList != null && selectedList.size() == 1);
itemExportSelection.setEnabled(selectedCol);
itemCopy.setEnabled(selectedCol);
if (allDataList.size() > 0) {
itemExportAll.setEnabled(true);
} else {
itemExportAll.setEnabled(false);
}
if (executer.getQueryEditor() != null && executer.getQueryEditor().getDatabaseInfo() != null && executer.getQueryEditor().getDatabaseInfo().equals(executer.getDatabaseInfo())) {
itemInsert.setEnabled(isEditMode());
itemDetail.setEnabled(enableItemDetail);
itemDelete.setEnabled(getEditable() && isEditMode());
} else {
itemInsert.setEnabled(false);
itemDetail.setEnabled(false);
itemDelete.setEnabled(false);
}
for (int i = 0; i < tblItems.length; i++) {
if (isEditMode() && getEditable() && tblItems[i].getText(1).equals(DataType.VALUE_NONE)) {
itemDelete.setEnabled(false);
}
}
}
});
itemCopy.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
copySelectedItems();
}
});
itemCopy.setAccelerator(SWT.CTRL + 'c');
itemDelete.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (isEditMode()) {
deleteRecord(tblResult, null);
}
}
});
itemExportAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportAllResults);
if (IDialogConstants.OK_ID == dialog.open()) {
ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), allColumnList, allDataList, false);
new ExecTaskWithProgress(task).exec();
}
}
});
// itemOid.addSelectionListener(new SelectionAdapter() {
// /**
// * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
// * @param event an event containing information about the
// * selection
// */
// public void widgetSelected(SelectionEvent event) {
// openOidNavigator(button2Position);
// }
//
// });
itemExportSelection.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportSelectedResults);
if (IDialogConstants.OK_ID == dialog.open()) {
ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), tblResult, selectableSupport.getSelectedTableItems(), false);
new ExecTaskWithProgress(task).exec();
}
}
});
itemMakeInsertQuery.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
String text = makeInsertQueryWithSelectedRecords();
CommonUITool.copyContentToClipboard(text);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
itemMakeUpdateQuery.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
String text = makeUpdateQueryWithSelectedRecords();
CommonUITool.copyContentToClipboard(text);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
Aggregations