Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-22549 - enhance jmx result dialogs to allow ctrl+c and context … #426

Merged
merged 1 commit into from
Jun 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@


import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
Expand All @@ -24,18 +34,56 @@
public abstract class AbstractTabularControlFactory
implements IAttributeControlFactory {

private void copyPressed(Table table) {
StringBuffer sb = new StringBuffer();
TableItem[] items = table.getSelection();
for( int i = 0; i < items.length; i++ ) {
sb.append(items[i].getText());
sb.append("\n"); //$NON-NLS-1$
}
String asString = sb.toString();
final Clipboard cb = new Clipboard(table.getDisplay());
if (asString.length() > 0) {
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[]{asString}, new Transfer[]{textTransfer});
}
}

public Control createControl(final Composite parent, final FormToolkit toolkit,
final boolean writable, final String type, final Object value,
final IWritableAttributeHandler handler) {

int style = SWT.SINGLE | SWT.FULL_SELECTION;
int style = SWT.MULTI | SWT.FULL_SELECTION;
Table table = null;
if (toolkit != null) {
table = toolkit.createTable(parent, style);
toolkit.paintBordersFor(parent);
} else {
table = new Table(parent, style | SWT.BORDER);
}

Menu menu = new Menu(table); // where table1 is your table
MenuItem item1 = new MenuItem(menu, SWT.PUSH);
item1.setText("Copy"); //$NON-NLS-1$
final Table table2 = table;
Listener popUpListener = new Listener() {
@Override
public void handleEvent(Event event) {
copyPressed(table2);
}
};
item1.addListener(SWT.Selection, popUpListener);
table.setMenu(menu);

table.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'c')) {
copyPressed(table2);
}
}
});



GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 20;
Expand Down