if(tableViewer.getTable().getSelection().length > 0) {
TableItem currentSelectedRow = tableViewer.getTable().getSelection()[0];
if(currentSelectedRow != null) {
CsvRow selectedRow = (CsvRow)currentSelectedRow.getData();
Clipboard clipboard = new Clipboard(getShell().getDisplay());
clipboard.setContents(new Object[] { selectedRow }, new Transfer[] { new CsvRowTransfer()});
}
}
}
};
public void focusLost(FocusEvent e) {
editor.getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), standardCopy);
editor.getEditorSite().getActionBars().updateActionBars();
}
public void focusGained(FocusEvent e) {
editor.getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), csvRowCopy);
editor.getEditorSite().getActionBars().updateActionBars();
}
});
tableViewer.getTable().addFocusListener(new FocusListener() {
IAction standardPaste = editor.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.PASTE.getId());
IAction csvRowPaste = new Action() {
public void run() {
Clipboard clipboard = new Clipboard(getShell().getDisplay());
try {
CsvRow entity = (CsvRow)clipboard.getContents(new CsvRowTransfer());
if(tableViewer.getTable().getSelection().length > 0) {
TableItem currentSelectedRow = tableViewer.getTable().getSelection()[0];
if(currentSelectedRow != null) {
CsvRow selectedRow = (CsvRow)currentSelectedRow.getData();
drop(entity, selectedRow);
}
}
} finally {
clipboard.dispose();
}
}
};
public void focusLost(FocusEvent e) {
editor.getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.PASTE.getId(), standardPaste);
editor.getEditorSite().getActionBars().updateActionBars();
}
public void focusGained(FocusEvent e) {
editor.getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.PASTE.getId(), csvRowPaste);
editor.getEditorSite().getActionBars().updateActionBars();
}
});
tableViewer.getTable().addFocusListener(new FocusListener() {
IAction standardCut = editor.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.CUT.getId());
IAction csvRowCut = new Action() {
public void run() {
Clipboard clipboard = new Clipboard(getShell().getDisplay());
if(tableViewer.getTable().getSelection().length > 0) {
TableItem currentSelectedRow = tableViewer.getTable().getSelection()[0];
if(currentSelectedRow != null) {
CsvRow selectedRow = (CsvRow)currentSelectedRow.getData();
clipboard.setContents(new Object[] { selectedRow }, new Transfer[] { new CsvRowTransfer()});
csvTable.remove(selectedRow);
refresh(RefreshMode.DATA);
setDirty(true);
}
}