use of org.eclipse.swt.dnd.Clipboard in project ACS by ACS-Community.
the class CopyDetailsToClipboardHandler method execute.
/**
* Receives the selection from the event detail part.
* <p>
* It may be my lack of understanding of good Eclipse 4 RCP practices that I wish
* I could handle the mouse menu action locally in the event detail part,
* instead of sending the data via selection service to separate handler.
* Perhaps to be refactored once this becomes clearer.
*/
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ParsedAnyData[] parsedAnyData) throws ExecutionException {
if (parsedAnyData == null || parsedAnyData.length == 0) {
return;
}
System.out.println("Will copy event details to the clipboard...");
// Convert selected table rows into a multi-line String
StringBuilder sb = new StringBuilder();
for (ParsedAnyData parsedAny : parsedAnyData) {
sb.append(parsedAnyDataToString(parsedAny));
}
// Write that data to the system clipboard
Clipboard cb = new Clipboard(Display.getCurrent());
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
cb.dispose();
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class ExportConnectionUtil method buttonPressed.
/**
* Call this method when the button in button bar is pressed
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == COPY_CLIPBOARD_ID) {
List<CubridDatabase> databaseList = getCheckedDatabases();
if (databaseList.size() <= 0) {
CommonUITool.openErrorBox(getShell(), Messages.expConDialogCopyErrorMsg);
return;
}
StringBuilder sb = new StringBuilder();
for (CubridDatabase db : databaseList) {
if (sb.length() > 0) {
sb.append(StringUtil.NEWLINE);
}
sb.append(NodeUtil.getJavaConnectionUrl(db.getDatabaseInfo()));
}
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.expConDialogCopySucessMsg);
return;
} else if (buttonId == IDialogConstants.OK_ID) {
if (!verify()) {
return;
}
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
String[] filterExtensions = new String[] { "*.xls" };
//Windows wild cards
dialog.setFilterExtensions(filterExtensions);
String fileName = dialog.open();
if (fileName == null) {
return;
}
/*Process the file extensions*/
if (!ExportConnectionUtil.isTxtFile(fileName) && !ExportConnectionUtil.isXlsFile(fileName) && !ExportConnectionUtil.isXlsxFile(fileName)) {
int filterIndex = dialog.getFilterIndex();
if (filterIndex == 0 || filterIndex == 2) {
fileName = fileName + ".xls";
} else if (filterIndex == 1) {
fileName = fileName + ".txt";
}
}
TaskExecutor taskExec = new CommonTaskExec(Messages.nameExportConnectionTask);
File file = new File(fileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
LOGGER.error("Create file failed:" + e.getMessage());
}
}
ExportConnectionsTask task = new ExportConnectionsTask(getCheckedDatabases(), file);
taskExec.addTask(task);
new ExecTaskWithProgress(taskExec).busyCursorWhile();
if (taskExec.isSuccess()) {
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgConnectionUrlExported);
super.okPressed();
}
}
super.buttonPressed(buttonId);
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class PstmtSQLDialog method createEmptyTable.
/**
* Create the empty parameter table
*
* @param parent Composite
* @param isMulti boolean
*/
protected void createEmptyTable(Composite parent) {
Group typeGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
GridData groupGd = new GridData(GridData.FILL_HORIZONTAL);
groupGd.heightHint = 70;
typeGroup.setLayoutData(groupGd);
typeGroup.setLayout(new GridLayout());
typeGroup.setText(Messages.colParaType);
parameterTypeTable = new Table(typeGroup, SWT.BORDER | SWT.H_SCROLL);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 45;
parameterTypeTable.setLayoutData(gd);
parameterTypeTable.setHeaderVisible(true);
parameterTypeTable.setLinesVisible(false);
parameterTypeTable.setDragDetect(false);
TableColumn columnNO = new TableColumn(parameterTypeTable, SWT.CENTER);
columnNO.setWidth(40);
columnNO.setText("");
tableEditor = new TableEditor(parameterTypeTable);
tableEditor.horizontalAlignment = SWT.LEFT;
tableEditor.grabHorizontal = true;
parameterTypeTable.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
if (event.button != 1) {
return;
}
if (isChanging) {
return;
}
Point pt = new Point(event.x, event.y);
final TableItem item = parameterTypeTable.getItem(0);
for (int i = 1; i < parameterTypeTable.getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
handleType(item, i);
}
}
}
});
Group parameterGroup = new Group(parent, SWT.SHADOW_IN);
parameterGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
parameterGroup.setLayout(new GridLayout(2, false));
parameterGroup.setText(Messages.colParaValue);
ToolBar toolBar = new ToolBar(parameterGroup, SWT.FLAT);
ToolItem addRecordItem = new ToolItem(toolBar, SWT.PUSH);
addRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_insert.png"));
addRecordItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addData();
}
});
ToolItem delRecordItem = new ToolItem(toolBar, SWT.PUSH);
delRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_delete.png"));
delRecordItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (parameterTable.getTable().getSelectionIndices().length == 0) {
setErrorMessage(Messages.errDeleteMsg);
return;
}
List<Integer> deleteIndex = new ArrayList<Integer>();
for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
deleteIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
}
int lastSelectedIndex = 0;
for (int i = 0; i < deleteIndex.size(); i++) {
int seletectIndex = deleteIndex.get(i);
int newIndex = seletectIndex - i;
valueList.remove(newIndex);
lastSelectedIndex = newIndex;
}
//reset the index in data
for (int i = 0; i < valueList.size(); i++) {
ParamValueObject paramValueObject = valueList.get(i);
paramValueObject.getValue().set(0, String.valueOf(i + 1));
}
parameterTable.setInput(valueList);
parameterTable.refresh();
if (parameterTable.getTable().getItemCount() > 0) {
parameterTable.getTable().setSelection(lastSelectedIndex < 1 ? 0 : lastSelectedIndex - 1);
parameterTable.getTable().setFocus();
}
validate();
}
});
parameterTable = new TableViewer(parameterGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
// press the tab key, it is moved next input area
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(parameterTable, new FocusCellOwnerDrawHighlighter(parameterTable));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(parameterTable) {
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION && ((MouseEvent) event.sourceEvent).button == 1) || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
// || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
TableViewerEditor.create(parameterTable, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
// new Table(parameterGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
parameterTable.getTable().setLayoutData(gridData);
parameterTable.getTable().setHeaderVisible(true);
parameterTable.getTable().setLinesVisible(true);
parameterTable.setUseHashlookup(true);
final TableViewerColumn columnNO2 = new TableViewerColumn(parameterTable, SWT.CENTER);
columnNO2.getColumn().setWidth(40);
columnNO2.getColumn().setText("");
parameterTable.setContentProvider(new ParamValueContentProvider());
parameterTable.setLabelProvider(new ParamValueLabelProvider(parameterTable.getTable()));
parameterTable.getTable().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'c') {
final Clipboard cb = new Clipboard(getShell().getDisplay());
StringBuffer clipboardDataString = new StringBuffer();
List<Integer> replaceIndex = new ArrayList<Integer>();
for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
}
for (int i = 0; i < replaceIndex.size(); i++) {
if (i != 0) {
clipboardDataString.append(EXCELDATASEPRATOR);
}
ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
for (int j = 1; j < parameterTypeTable.getColumnCount(); j++) {
if (j != 1) {
clipboardDataString.append(EXCELCOLUMNSEPRATOR);
}
String value = paramValueObject.getValue().get(j);
clipboardDataString.append(value);
}
}
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { clipboardDataString.toString() };
cb.setContents(data, transfers);
cb.dispose();
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'v') {
final Clipboard cb = new Clipboard(getShell().getDisplay());
// boolean supportFlag = false;
// TransferData[] transferDatas = cb.getAvailableTypes();
// for(int i=0; i<transferDatas.length; i++) {
// // Checks whether RTF format is available.
// if(RTFTransfer.getInstance().isSupportedType(transferDatas[i])) {
// supportFlag = true;
// break;
// }
// }
// if (!supportFlag) {
// setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
// return;
// }
String plainText = (String) cb.getContents(TextTransfer.getInstance());
List<ParamValueObject> list = generateParamValueObjectListFromClipboardString(plainText);
if (list.size() == 0 || list.get(0).getValue().size() != parameterTypeTable.getColumnCount()) {
setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
return;
}
// String rtfText = (String)cb.getContents(RTFTransfer.getInstance());
int startIndex = parameterTable.getTable().getSelectionIndex();
//if the copy line bigger than the value list, add new ParamValueObject to the end
if (parameterTable.getTable().getSelectionCount() <= 1) {
if (startIndex < 0 || startIndex > valueList.size()) {
for (ParamValueObject copyParamValueObject : list) {
valueList.add(copyParamValueObject);
}
} else {
for (ParamValueObject copyParamValueObject : list) {
if (startIndex > valueList.size() - 1) {
valueList.add(copyParamValueObject);
} else {
ParamValueObject paramValueObject = valueList.get(startIndex);
List<String> oldValue = paramValueObject.getValue();
for (int i = 1; i < oldValue.size(); i++) {
List<String> newValue = copyParamValueObject.getValue();
if (i > newValue.size() - 1) {
break;
}
oldValue.set(i, newValue.get(i));
}
}
startIndex++;
}
}
} else {
// replay the select line
List<Integer> replaceIndex = new ArrayList<Integer>();
for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
}
for (int i = 0; i < replaceIndex.size(); i++) {
ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
List<String> oldValue = paramValueObject.getValue();
if (i > list.size()) {
break;
}
List<String> newValue = list.get(i).getValue();
for (int j = 1; j < oldValue.size(); j++) {
if (j > newValue.size()) {
break;
}
oldValue.set(j, newValue.get(j));
}
}
}
cb.dispose();
refreshValueListIndex();
parameterTable.refresh();
validate();
}
}
});
// use to mark click point, the right click menu use this point
parameterTable.getTable().addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
clickPoint = new Point(event.x, event.y);
}
});
registerContextMenu();
parameterTable.setInput(valueList);
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class MultiDBQueryComposite method initialize.
/**
* Create the SQL history composite
*/
public void initialize() {
Composite toolBarComposite = new Composite(this, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 0;
gridLayout.horizontalSpacing = 10;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
toolBarComposite.setLayout(gridLayout);
toolBarComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
ToolItem refreshToolItem = new ToolItem(toolBar, SWT.PUSH);
refreshToolItem.setText(Messages.lblItemRefreshMulti);
refreshToolItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
refreshToolItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
refreshToolItem.setToolTipText(Messages.refresh);
refreshToolItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//refresh may set tree to group type or not
//so mark the select db then set it to checked after set input
// Object[] checkedObject = ctv.getCheckedElements();
setInput();
// for (Object o : checkedObject) {
// if (o instanceof CubridDatabase) {
// ctv.setChecked(o, true);
// }
// }
// refresh(editor.getSelectedDatabase());
}
});
runItem = new ToolItem(toolBar, SWT.PUSH);
runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
runItem.setText(Messages.lblItemRunMulti);
runItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
editor.runMultiQuery();
}
});
Label lblNotice = new Label(toolBarComposite, SWT.None);
lblNotice.setText(Messages.qedit_multiDBQueryComp_noticeToolbarMsg);
lblNotice.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
// create the query result tab folder
multiDBQueryCompTabFolder = new CTabFolder(this, SWT.BOTTOM);
multiDBQueryCompTabFolder.setSimple(false);
multiDBQueryCompTabFolder.setUnselectedImageVisible(true);
multiDBQueryCompTabFolder.setUnselectedCloseVisible(true);
multiDBQueryCompTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
multiDBQueryCompTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
multiDBQueryCompTabFolder.setLayout(new GridLayout(1, true));
multiDBQueryCompTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
//TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(multiDBQueryCompTabFolder);
//tabContextMenuManager.createContextMenu();
multiDBQueryCompTabItem = new CTabItem(resultTabFolder, SWT.NONE);
multiDBQueryCompTabItem.setText(Messages.qedit_multiDBQueryComp_folder);
multiDBQueryCompTabItem.setControl(this);
multiDBQueryCompTabItem.setShowClose(false);
SashForm bottomSash = new SashForm(multiDBQueryCompTabFolder, SWT.VERTICAL);
bottomSash.SASH_WIDTH = SASH_WIDTH;
bottomSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
SashForm tailSash = new SashForm(bottomSash, SWT.HORIZONTAL);
tailSash.SASH_WIDTH = SASH_WIDTH;
tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
Composite treeComp = new Composite(tailSash, SWT.NONE);
{
treeComp.setLayoutData(new GridData(GridData.FILL_BOTH));
treeComp.setLayout(new GridLayout());
}
ctv = new ContainerCheckedTreeViewer(treeComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
ctv.setContentProvider(new MultiDBQueryTreeContentProvider());
ctv.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
if (lastSelectedTime != 0 && lastSelectedTime > System.currentTimeMillis()) {
ctv.setChecked(event.getElement(), true);
return;
}
ctv.setChecked(event.getElement(), false);
lastSelectedTime = System.currentTimeMillis() + 100;
if (getQueryDatabaseList().size() > 0 && editor.getAllQueries().trim().length() != 0) {
editor.setMultiQueryRunItemStatus(true);
} else if (getQueryDatabaseList().size() == 0) {
editor.setMultiQueryRunItemStatus(false);
}
//if (!event.getChecked()) {
selectedNodes.remove(event.getElement());
if (event.getElement() instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) event.getElement();
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
//ctv.setChecked(event.getElement(), false);
selectedNodes.remove(database);
} else {
if (database.getData(INDEXKEY) == null) {
database.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
}
} else if (event.getElement() instanceof CubridServer) {
CubridServer serverNode = (CubridServer) event.getElement();
for (ICubridNode dbFolderNode : serverNode.getChildren()) {
for (ICubridNode dbNode : dbFolderNode.getChildren()) {
if (dbNode instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) dbNode;
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
//ctv.setChecked(dbNode, false);
selectedNodes.remove(database);
} else if (ctv.getChecked(dbNode)) {
ctv.setChecked(dbNode, true);
if (dbNode.getData(INDEXKEY) == null) {
dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
} else {
ctv.setChecked(dbNode, true);
}
}
}
//only has one db folder so first time break it
break;
}
} else if (event.getElement() instanceof ICubridNode) {
ICubridNode node = (ICubridNode) event.getElement();
if (node.getType().equals(NodeType.DATABASE_FOLDER)) {
for (ICubridNode dbNode : node.getChildren()) {
if (dbNode instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) dbNode;
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
ctv.setChecked(dbNode, false);
} else if (ctv.getChecked(dbNode)) {
ctv.setChecked(dbNode, true);
if (dbNode.getData(INDEXKEY) == null) {
dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
} else {
ctv.setChecked(dbNode, false);
}
}
}
}
// else if (node.getType().equals(NodeType.GROUP)) {
// for (ICubridNode childNode : node.getChildren()) {
// //CQB tree
// if(childNode instanceof CubridDatabase) {
// CubridDatabase database = (CubridDatabase) childNode;
// if (database.getRunningType() == DbRunningType.STANDALONE
// || !database.isLogined()) {
// if (childNode.getData(INDEXKEY) == null) {
// childNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
// }
// }
// continue;
// }
// //CM tree
// for (ICubridNode dbFolderNode : childNode.getChildren()) {
// for (ICubridNode dbNode : dbFolderNode.getChildren()) {
// if(dbNode instanceof CubridDatabase) {
// CubridDatabase database = (CubridDatabase) dbNode;
// if (database.getRunningType() == DbRunningType.STANDALONE
// || !database.isLogined()) {
// ctv.setChecked(dbNode, false);
// } else if (ctv.getChecked(dbNode)) {
// ctv.setChecked(dbNode, true);
// if (dbNode.getData(INDEXKEY) == null) {
// dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
// }
// } else {
// ctv.setChecked(dbNode, false);
// }
// }
// }
// }
// //only has one db folder so first time break it
// break;
// }
// }
}
ctv.refresh();
}
});
ctv.getTree().addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent event) {
//mac can't drag and drop,so support copy and paste db node
if (((event.stateMask & SWT.CTRL) != 0) || ((event.stateMask & SWT.COMMAND) != 0) && event.keyCode == 'v') {
final Clipboard cb = new Clipboard(getShell().getDisplay());
String plainText = (String) cb.getContents(TextTransfer.getInstance());
String[] databaseNameArray = plainText.split(",");
selectedNodes.addAll(getDatabaseNode(databaseNameArray));
setInput();
}
}
});
// ctv.addDoubleClickListener(LayoutManager.getInstance());
// ctv.addTreeListener(new ITreeViewerListener() {
// public void treeCollapsed(TreeExpansionEvent event) {
// CommonTool.clearExpandedElements(ctv);
// }
//
// public void treeExpanded(TreeExpansionEvent event) {
// CommonTool.clearExpandedElements(ctv);
// }
// });
final Tree tableTree = ctv.getTree();
tableTree.setHeaderVisible(true);
tableTree.setLinesVisible(true);
final TreeViewerColumn dbCol = new TreeViewerColumn(ctv, SWT.NONE);
dbCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
dbCol.getColumn().setWidth(250);
dbCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_dbCol);
final TreeViewerColumn indexCol = new TreeViewerColumn(ctv, SWT.NONE);
indexCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
indexCol.getColumn().setWidth(50);
indexCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_indexCol);
indexCol.setEditingSupport(new EditingSupport(ctv) {
TextCellEditor textCellEditor;
protected boolean canEdit(Object element) {
if (element instanceof ICubridNode) {
ICubridNode node = (ICubridNode) element;
if (node.getType() == NodeType.DATABASE) {
CubridDatabase database = (CubridDatabase) element;
if ((database.getRunningType() == DbRunningType.CS && database.isLogined())) {
return true;
}
}
}
return false;
}
protected CellEditor getCellEditor(Object element) {
if (textCellEditor == null) {
textCellEditor = new TextCellEditor(ctv.getTree());
textCellEditor.setValidator(new IndexCellEditorValidator());
textCellEditor.addListener(new ICellEditorListener() {
public void applyEditorValue() {
}
public void cancelEditor() {
}
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
}
});
}
return textCellEditor;
}
protected Object getValue(Object element) {
final ICubridNode node = (ICubridNode) element;
String index = (String) node.getData(INDEXKEY);
if (index == null) {
return "";
} else {
return index;
}
}
protected void setValue(Object element, Object value) {
if (value == null) {
return;
}
try {
Integer.valueOf((String) value);
} catch (Exception e) {
return;
}
final ICubridNode node = (ICubridNode) element;
node.setData(INDEXKEY, value);
// setAllParentExpandOrCollapse(node.getParent(), true);
ctv.refresh();
}
/**
* MyCellEditorValidator
*
* @author fulei
*
*/
class IndexCellEditorValidator implements ICellEditorValidator {
/**
* isValid
*
* @param value Object
* @return String
*/
public String isValid(Object value) {
try {
Integer.valueOf((String) value);
} catch (Exception e) {
CommonUITool.openErrorBox(Messages.qedit_multiDBQueryComp_tree_indexErr);
return Messages.qedit_multiDBQueryComp_tree_indexErr;
}
return null;
}
}
});
final TreeViewerColumn commentCol = new TreeViewerColumn(ctv, SWT.NONE);
commentCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
commentCol.getColumn().setWidth(200);
commentCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_commentCol);
CTabItem tabItem = new CTabItem(multiDBQueryCompTabFolder, SWT.NONE);
tabItem.setText(Messages.qedit_multiDBQueryComp_tabItem);
tabItem.setControl(bottomSash);
tabItem.setShowClose(false);
setInput();
// HostNodePersistManager.getInstance().getAllServer();
multiDBQueryCompTabFolder.setSelection(tabItem);
dragController = new MultiDBQueryDNDController(this, ctv);
dragController.registerDropTarget();
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class ParamDumpResultDialog method createDialogArea.
/**
* @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
* @param parent The parent composite to contain the dialog area
* @return the dialog area control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.numColumns = 5;
composite.setLayout(layout);
//dynamicHelp end
createdbNameGroup(composite);
table = new Table(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
table.setHeaderVisible(true);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.horizontalSpan = 7;
gridData.verticalSpan = 10;
gridData.heightHint = 300;
table.setLayoutData(gridData);
table.setLinesVisible(true);
CommonUITool.hackForYosemite(table);
/*
* // fill in context menu
*/
Menu menu = new Menu(parent.getShell(), SWT.POP_UP);
table.setMenu(menu);
MenuItem copy = new MenuItem(menu, SWT.PUSH);
copy.setText(Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.contextCopy, "Ctrl+C"));
copy.setAccelerator(SWT.CTRL + 'C');
copy.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
StringBuilder content = new StringBuilder();
TableItem[] items = table.getSelection();
for (int i = 0; i < items.length; i++) {
content.append(items[i].getText(0) + blank + items[i].getText(1) + blank + items[i].getText(2) + blank + System.getProperty("line.separator"));
}
String data = content.toString();
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
});
table.addKeyListener(new org.eclipse.swt.events.KeyAdapter() {
public void keyPressed(org.eclipse.swt.events.KeyEvent event) {
if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0 && event.keyCode == 'c') {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
StringBuilder content = new StringBuilder();
TableItem[] items = table.getSelection();
for (int i = 0; i < items.length; i++) {
content.append(items[i].getText(0) + blank + items[i].getText(1) + blank + items[i].getText(2) + blank + System.getProperty("line.separator"));
}
String data = content.toString();
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
}
});
setTitle(Messages.titleParamDumpDialog);
setMessage(Messages.msgParamDumpDialog);
initial();
return parentComp;
}
Aggregations