Example showing Multi Edit in Nattable - nattable

I have a requirement wherein on a single click in the cell, normal editing must be possible and on double clicking in the cell a dialog should open for editing the cell. The two are possible individually. I see a method "boolean supportMultiEdit(IConfigRegistry configRegistry, List configLabels)" but there is no example to show the working. Has anyone used it or can show it's configuration.

Multi edit means it is possible to edit multiple cells at once. This is of course done in an editor, as it makes no sense to perform multi edit inline. You should rather have a look at openInline(IConfigRegistry, List<String>) or even better the EditConfigAttributes#OPEN_IN_DIALOG to solve what you are looking for.
But you are actually seeking for a way to handle opening an editor differently on different UI interactions. So you need to register the corresponding UI bindings. This is already discussed in the NatTable Forum.
And the EditorExample shows quite a lot of possible configuration options available for editing. And almost every editable example shows multi editing capabilities. You simply need to select multiple cells you want to edit and then start typing or pressing F2.
The following code would do the trick with a configuration based on a label that is added in the UI binding action:
public class OpenEditorConfiguration extends AbstractRegistryConfiguration {
#Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(
EditConfigAttributes.OPEN_IN_DIALOG,
Boolean.TRUE,
DisplayMode.EDIT,
"open_in_dialog");
}
#Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerDoubleClickBinding(
new CellEditorMouseEventMatcher(GridRegion.BODY),
new IMouseAction() {
#Override
public void run(NatTable natTable, MouseEvent event) {
int columnPosition = natTable.getColumnPositionByX(event.x);
int rowPosition = natTable.getRowPositionByY(event.y);
ILayerCell cell = natTable.getCellByPosition(columnPosition, rowPosition);
cell.getConfigLabels().add("open_in_dialog");
natTable.doCommand(new EditCellCommand(
natTable,
natTable.getConfigRegistry(),
cell));
}
});
}
}

Related

How to clear the selection in the selection service Eclipse RCP?

How do I clear the selection in my Eclipse RCP application?
Basically I would like to clear it on escape key down:
Display display = PlatformUI.createDisplay();
display.addFilter(SWT.KeyDown, new Listener() {
#Override
public void handleEvent(Event event) {
if (event.character == SWT.ESC) {
// if this is escape key, clear selection in the application
}
}
});
I thought I would be able to do something like PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().clearSelection()/setSelection(IStructuredSelection.EMPTY), but no go.
You need to look up the ISelectionProvider rather than the ISelectionService. That will provide you with a setSelection() method.
You can get the selction provider from the site:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getSelectionProvider();
or
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite().getSelectionProvider();
Note that some of those return values could be null so add the appropriate checks.
You can't clear the selection provided by the selection service directly.
The selection the service returns is provided by a 'selection provider' (ISelectionProvider) for the current part.
You can get the selection provider from an IWorkbenchPart with IWorkbenchPart.getSite().getSelectionProvider().
ISelectionProvider has a setSelection method but it often does nothing or throws an exception so you may not be able to clear the selection.

Making Ctrl-C copy from whichever SourceViewer has focus in Eclipse plug-in

I successfully extended the PyDev editor in Eclipse with a side-by-side display, but I can't copy the contents of the extra SourceViewer that I added. I can select some text in the display, but when I press Ctrl+C, it always copies the main PyDev editor's selected text.
I found an article on key bindings in Eclipse editors, but the code there seems incomplete and a bit out-of-date. How can I configure the copy command to copy from whichever SourceViewer has focus?
The reason I want to do this is that I've written a tool for live coding in Python, and it would be much easier for users to submit bug reports if they could just copy the display and paste it into the bug description.
David Green's article was a good start, but it took a bit of digging to make it all work. I published a full example project on GitHub, and I'll post a couple of snippets here.
The TextViewerSupport class wires up a new action handler for each command you want to delegate to the extra text viewer. If you have multiple text viewers, just instantiate a TextViewerSupport object for each of them. It wires up everything in its constructor.
public TextViewerSupport(TextViewer textViewer) {
this.textViewer = textViewer;
StyledText textWidget = textViewer.getTextWidget();
textWidget.addFocusListener(this);
textWidget.addDisposeListener(this);
IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
handlerService = (IHandlerService) window
.getService(IHandlerService.class);
if (textViewer.getTextWidget().isFocusControl()) {
activateContext();
}
}
The activateContext() method has a list of all the commands you want to delegate, and registers a new handler for each one. This was one of the changes from David's article; his ITextEditorActionDefinitionIds has been deprecated and replaced with IWorkbenchCommandConstants.
protected void activateContext() {
if (handlerActivations.isEmpty()) {
activateHandler(ITextOperationTarget.COPY,
IWorkbenchCommandConstants.EDIT_COPY);
}
}
// Add a single handler.
protected void activateHandler(int operation, String actionDefinitionId) {
StyledText textWidget = textViewer.getTextWidget();
IHandler actionHandler = createActionHandler(operation,
actionDefinitionId);
IHandlerActivation handlerActivation = handlerService.activateHandler(
actionDefinitionId, actionHandler,
new ActiveFocusControlExpression(textWidget));
handlerActivations.add(handlerActivation);
}
// Create a handler that delegates to the text viewer.
private IHandler createActionHandler(final int operation,
String actionDefinitionId) {
Action action = new Action() {
#Override
public void run() {
if (textViewer.canDoOperation(operation)) {
textViewer.doOperation(operation);
}
}
};
action.setActionDefinitionId(actionDefinitionId);
return new ActionHandler(action);
}
The ActiveFocusControlExpression gives the new handler a high enough priority that it will replace the standard handler, and it's almost identical to David's version. However, to get it to compile, I had to add extra dependencies to my plug-in manifest: I imported packages org.eclipse.core.expressions and org.eclipse.ui.texteditor.

How can I display all possible values in a SuggestBox

I would like to display all possible values in a SuggestBox.
Naturally, I have the following code (settingName is a SuggestBox)
settingName.getTextBox().addFocusHandler(new FocusHandler() {
#Override
public void onFocus(FocusEvent event) {
settingName.showSuggestionList();
}
});
Unfortunately, the suggestbox displays anything. Of course, the settingName is associated to an oracle with several values inside it.
Am I crazy ?
According to the documentation :
public void showSuggestionList()
Show the current list of suggestions.
You need to set the defaults to show by suggestOracle.setDefaultSuggestionsFromText(..)
When showing the list, the SuggestBox will ask the oracle for values to show. If the text box is empty, then requestDefaultSuggestions will be called (which by default calls requestSuggestions).

How to add a double-click listener to my GEF editor?

I'm using GEF. I have a graphical editor with some "boxes" implemented. Now, I want to add a double-click listener to each box (Rectangle).
I tried to add a listener to the GraphicalViewer but it did not work.
In the GraphicalEditPart of the "box" for which you want to add the listener, you have to override the performRequest(Request req) method. When the framework identifies a double-click on the part's figure, it calls this method with a request that has req.getType()==RequestConstants.REQ_OPEN. You can take over from here.
Complete code to test that his works:
#Override
public void performRequest(Request req) {
if(req.getType() == RequestConstants.REQ_OPEN) {
System.out.println("requested double-click.");
}
}
Hope this does the trick.
I am not familiar with GEF myself, however I found this in documentation:
GraphicalEditor abstraction sets the EditDomain - handler for editing events
EditDomain interface with methods for handling events - e.g. double click
Tutorial on how to implement editing of models through GUI in GEF (using EditDomain)
viewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() {
#Override
public void handleEvent(Event event) {
//write the double click action
});

GWT, disable autoclose MenuBar when clicking on MenuItem?

I want to if it is possible to disable the auto-close MenuBar when I click on a MenuItem?
I have several MenuItem that are like checkboxes, so I can check more than one MenuItem and don't want my menu close everytime I checked one.
Thanks.
I was facing same problem and I will share with you my solution:
1) Create new class MyMenuItemWithCheckBox that extends the MenuItem.
In the constructor set element ID to (forexample) menuItemWIthCheckBox + Unique text.
this.getElement().setId("menuItemWithCheckBox_" + menuItemLabel);
2) Create new class MyMenuBar that extends the MenuBar.
Override the onBrowserEvent method by following:
Override
public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK && getSelectedItem().getElement().getId().contains("CheckBox")) {
Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
#Override
public void execute() {
getSelectedItem().getScheduledCommand().execute();
}
});
event.stopPropagation();
} else {
super.onBrowserEvent(event);
}
}
Now scheduled command of MenuItem is always called, but in the case of your
menu checkBox item there is no close of a menubar.
I hope this help you, I spend more than day to create this solution. :-)
First, directly it's not possible because the popup-panel which displays the submenu is private in the MenuBar class.
Buuut, there is a way to do so ...
Simpley fetch the current MenuBar.java code out of googles code repository and include it in your eclipse gwt-project.
You don't have to change anything e.g. package deklaration or something. Just put your source in your project and it will simply replace the original MenuBar-class from the gwt-sdk during compilation (works also with hosted development mode).
Then you can simply set the property autoHide of the popup-Panel to false and the popup shouldn't disappear after clicking.
You can set hideOnClick to false on the menuItems
See here.