Eclipse - custom launch configuration - apply/revert buttons - java

I'm making my custom launch configuration type. I implemented the launch configuration tab and faced the strange problem. When I do the following
private void update() {
setDirty(true);
updateLaunchConfigurationDialog();
}
in one place of my launch configuration tab class, it works fine and Apply button becomes enabled. But when I do it in another place, it doesn't work. I found something similar at https://www.eclipse.org/forums/index.php/t/164755/ , but it didn't help me to solve this problem.
See the code fragments below.
addButton.addMouseListener(new MouseListenerAdapter() {
#Override
public void mouseDown(MouseEvent e) {
moveSelectionToTableViewer(tree.getViewer().getTree().getSelection());
table.refresh();
update(); // Apply button is enabled
}
private void moveSelectionToTableViewer(TreeItem[] selection) {
// ...
}
});
removeButton.addMouseListener(new MouseListenerAdapter() {
#Override
public void mouseDown(MouseEvent e) {
int[] selectionIndices = table.getTable().getSelectionIndices();
table.getTable().remove(selectionIndices);
tree.getViewer().refresh();
update(); // Apply button is NOT enabled!
}
});
How can I solve this?

I don't know your problem from this information alone, But just a few things to check:
Have you verified that setDirty(true) is being called (e.g. with println or breakpoint?)
Have you put a watch on org.eclipse.debug.ui.AbstractLaunchConfigurationTab.fDirty to see if it changes back?
Are you overriding isDirty?
Is removing the an item from the table causing the launch configuration to become invalid in some way, i.e. you can't Apply when invalid values are in the launch config. For example, to be saveable, canSave must return true for all the tabs that are part of the launch configuration.
This is (one of the) place(s) that sets the enabled state of the Apply button:
org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer.updateButtons()
/**
* updates the button states
*/
private void updateButtons() {
boolean dirty = isDirty() && canSave();
fApplyButton.setEnabled(dirty);
fRevertButton.setEnabled(dirty);
}
Consider if a mouse listener is what you want. Note that you are responding to MouseDown, that may not do what you expect if a person tabs over to the control and presses Enter/Space instead. The more typical thing to do would be an addSelectionListener for a button. (Could it even be that responding to the event at this unusual time is causing the problem?)

Related

(GXT) Change registration in ALL Children of Popup Panel

I have the following Problem in my GXT-Application:
In a Popup-Panel, I have a bunch of different fields, which are to be saved in a Databse (see picture)
I would add a new feature, which recogizes changes in the Children of this Popup-Panel. For this reason, I added a Change-Event to the Popup-Panel:
editorPanel.addHandler(new ChangeHandler() {
#Override
public void onChange(ChangeEvent event) {
Info.display("Change","Now");
}
}, ChangeEvent.getType());
My Problem is now, that this only works with DataFields but not with Comboboxes. As far as I understood, this is due to the fact, that Comboboxes do not have a Change-Event but a Select-Event.
And here is my question: Is there an elegant way to gat those changes on the Level of the Popup-Panel or do I have to thriger the change event by every selection?
Sincerely,
Erik

Add listener jDateChooser

i haved create this metod for add listeners in my dataChooser.
public final void añadirEsccuhaDataChoser() {
jDateChooser1.getDateEditor().addPropertyChangeListener((PropertyChangeEvent e) -> {
if ("date".equals(e.getPropertyName())) {
listarviajes1();
}
});
this.add(jDateChooser1);
}
but the result who i have obtened after run the project is this.
datachooser moved
but the my original desing is this.
data chooser original position
the method i haved situate into the public vReservas().
situation method
What can I do to prevent the dataChooser from moving?
this is a solution.
solution
The problem is that I created a method, instead of adding the listener in the JdateChooser's internal code.
The code to add the listener is the same, just place it in the custom code option of the jDateChooser.
the ubication of listener

Eclipse plugin: Properties information not shown correctly when treeview is part of a tabfolder/tabitem

I am developing an eclipse plug in with a tree viewer. Initially I had a single treeview of which I have displayed information of some elements in the standard eclipse properties tab. That worked without problems.
I have followed an example where I implement the IPropertySource and IAdapterFactory. In the method createPartControl() of the view I call
getSite().setSelectionProvider(searchViewer);
which registers the properties.
Now I have added an swt tabfolder item to the plug in. Now In every new tabitem a treeview is displayed. That works fine, but the information in the properties tab are not shown correctly anymore. There's a strange behaviour though. On the tree elements which are of interest I have also added a doubleclick listener to do other things. After I double click an entry and right after single click on another element, the properties are shown for the doubleclicked element?!
I guess the problem is with the SelectionProvider. But I was not able to figure out how to implement it correctly now
The properties view always shows the properties for the object that the selection provider says is the current selection.
If you have multiple tree views on several tabs you will have to write a custom selection provider (ISelectionProvider) that knows which tree is currently active and provides the appropriate selection.
For example, the following is a selection provider used by the JDT code for some things which you could use as a base:
public class SimpleSelectionProvider implements ISelectionProvider {
private final ListenerList<ISelectionChangedListener> fSelectionChangedListeners;
private ISelection fSelection;
public SimpleSelectionProvider() {
fSelectionChangedListeners = new ListenerList<>();
}
#Override
public ISelection getSelection() {
return fSelection;
}
#Override
public void setSelection(ISelection selection) {
fSelection= selection;
for (ISelectionChangedListener listener : fSelectionChangedListeners) {
listener.selectionChanged(new SelectionChangedEvent(this, selection));
}
}
#Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
fSelectionChangedListeners.remove(listener);
}
#Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {
fSelectionChangedListeners.add(listener);
}
}
(org.eclipse.jdt.internal.ui.actions.SimpleSelectionProvider)
You would have to make all your trees call the setSelection method when selections change.

Vaadin SuperDevMode recompilation fails sometimes, Widget is not rendered as it should and Java code for the Widget is not available

I am trying to set up the SuperDevMode on a Vaadin project.
I have basically 3 problems related to this feature.
I have the following widget (created using the "New Vaadin Widget" wizard, below the code for the client-side widget, connector, state and server-side component):
// Widget:
public class CountedTextFieldWidget extends Composite {
private TextBox textBox = new TextBox();
private Label countLabel = new Label("0");
private HorizontalPanel panel = new HorizontalPanel();
public static final String CLASSNAME = "countedtextfield";
public CountedTextFieldWidget() {
initWidget(panel);
setStylePrimaryName(CLASSNAME);
textBox.setStylePrimaryName(CLASSNAME + "-field");
countLabel.setStylePrimaryName(CLASSNAME + "-label");
setStylePrimaryName(CLASSNAME);
panel.add(textBox);
panel.add(countLabel);
}
public String getText() {
return textBox.getText();
}
public void setText(String text) {
textBox.setText(text);
}
public void setCount(int count) {
countLabel.setText("" + count);
}
public int getCount() {
return Integer.parseInt(countLabel.getText());
}
// HandlerRegistration can be used to remove the key up handler (listener)
// added with this method
public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
return textBox.addKeyUpHandler(handler);
}
}
/********************************************************/
// Connector:
#Connect(CountedTextField.class)
public class CountedTextFieldConnector extends AbstractComponentConnector {
public CountedTextFieldConnector() {
getWidget().addKeyUpHandler(new KeyUpHandler() {
#Override
public void onKeyUp(KeyUpEvent event) {
String text = getWidget().getText();
getWidget().setCount(text.length());
}
});
}
#Override
protected Widget createWidget() {
return GWT.create(CountedTextFieldWidget.class);
}
#Override
public CountedTextFieldWidget getWidget() {
return (CountedTextFieldWidget) super.getWidget();
}
#Override
public CountedTextFieldState getState() {
return (CountedTextFieldState) super.getState();
}
#Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
final String text = getState().text;
getWidget().setText(text);
getWidget().setCount(text.length());
}
}
/********************************************************/
// State
public class CountedTextFieldState extends com.vaadin.shared.ui.textfield.AbstractTextFieldState {
{
primaryStyleName = null;
}
}
/********************************************************/
// Server-side component:
public class CountedTextField extends com.vaadin.ui.TextField {
#Override
public String getValue() {
return getState().text;
}
public void setValue(String value) {
getState().text = value;
}
#Override
public CountedTextFieldState getState() {
return (CountedTextFieldState) super.getState();
}
}
This widget is rendered as following:
Now, I have followed the following guide on the Vaadin's wiki:
https://vaadin.com/wiki/-/wiki/Main/Using%20SuperDevMode
The CodeServer starts as expected:
The code server is ready.
Next, visit: http://localhost:9876/
But when I open the project and append ?superdevmode to the URL, get the Recompilation failed... message and there's are some errors in the browser's console:
So my first problem is related to this issue:
1) Why does recompilation fail sometimes? And what are those SEVERE: JSONP compile call failed and SEVERE: Timeout Excecution?
Then if I ... click to retry sometimes the superdevmode starts, but the custom widget is not rendered as in the previous screenshot I posted.
Instead, I get a standard Vaadin's v-textfield...
2) WTF... Why? Where is my custom component?
I noticed that I get the same issue also if I open localhost:9876, drag the Dev Mode On button to the bookmarks toolbar and then click on it while on localhost:8080/project. My custom widget is disappears and instead I get the Vaadin's v-textfield widget...
And about the Enable Source Map feature. On the wiki, they say:
To be able to debug Java code in Chrome, open the Chrome Inspector
(right click -> Inspect Element), click the settings icon in the lower
corner of the window and check "Scripts -> Enable source maps".
Refresh the page with the inspector open and you will see Java code
instead of JavaScript code in the scripts tab.
In my Chrome, I don't have a settings icon on the lower corner of the window, I clicked the gear icon on the right and went to General -> Sources and checked Enable JavaScript Source Map (There's no generic Enable source maps entry on my settings tab).
I can see the Java sources, but they are all sources for GWT and Vaadin's components:
So my third issue and related question:
3) How can I see my custom widget code also?
Thanks for the attention! Hope I was clear.
I also had a similar problem trying to use SuperDev Mode with Vaadin. I'm not quite sure why recompilation fails on occasion, but I suspect it envolves the same issue I had trying to send my Java source maps. The problem I had seemed to be a caching issue due to the fact that the code server creates a persistent cache directory in my /tmp folder. So I deleted every folder it created (they usually have "gwt" in the name somewhere) and relaunched the code server. I suggest also adding the -src <complete-path-to-project> argument in the code server configurations to specify the directory containing GWT source to be prepended to the classpath for compiling and possibly changing the log level to TRACE or DEBUG. Heres an example those arguments:
com.example.AppWidgetSet -src /home/workspace/widgetset/src/main/java
-logLevel TRACE
I should mention that the log levels are quite verbose, but can be quite useful. The log should also show the location of the cache folder.

GWT SuggestBox: How do I force the SuggestBox to select the first item in the suggestion list?

I have a textbox and one suggestbox. I attach a value change and key up handler to the text box such that whatever the user types (or pastes) into the text box is echo-ed inside the suggestbox. I can get the suggestbox to display the suggestion list by calling showSuggestionList on each value change and key up event.
Now, how do I get the suggestbox to automatically choose the first item in the suggestion list?
One of the methods I tried is to programatically simulate key presses, i.e
suggestBox.setFocus(true);
NativeEvent enterEvent = Document.get().createKeyPressEvent(false, false, false, false, KeyCodes.KEY_ENTER);
DomEvent.fireNativeEvent(enterEvent, suggestBox);
textBox.setFocus(true);
This doesn't work at all. The enter key isn't simulated. Another possible solution is to extend SuggestionBox.SuggestionDisplay, but I'm not too sure how to that. Any pointers appreciated.
Update: I'm still working on this and trying various methods.
Here, I tried to implement my own SuggestionDisplay by subclassing DefaultSuggestionDisplay and overriding getCurrentSelection() to make accessible from my class. This doesn't work either. Null is returned.
private class CustomSuggestionDisplay extends DefaultSuggestionDisplay {
#Override
protected Suggestion getCurrentSelection() {
return super.getCurrentSelection();
}
}
suggestBox.setAutoSelectEnabled(true);
textBox.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
suggestBox.setValue(textBox.getText(), true);
suggestBox.showSuggestionList();
if (suggestBox.isSuggestionListShowing()) {
String s = ((CustomSuggestionDisplay) suggestBox.getSuggestionDisplay()).getCurrentSelection().getDisplayString();
Window.alert(s);
}
}
});
Here, I tried to attach a value change handler to the SuggestBox, and casting the event type to SuggestOracle.Suggestion. Again, null is returned.
suggestBox.addValueChangeHandler(new ValueChangeHandler<String>() {
public void onValueChange(ValueChangeEvent<String> event) {
String s = ((SuggestOracle.Suggestion) event).getDisplayString();
Window.alert(s);
}
});
Use suggesBox.setAutoSelectEnabled(true)
Here more info about the SuggestBox of GWT:
You could try using addSelectionHandler in conjunction with setAutoSelectEnabled to receive an event whenever a suggestion is selected. You could also have your Oracle send a message when it suggests something, or your Display send a message when it displays a list:
public class AutomaticallySelectingSuggestionDisplay extends SuggestBox.DefaultSuggestionDisplay {
#Override
protected void showSuggestions(SuggestBox box, Collection<? extends SuggestOracle.Suggestion> suggestions, boolean isDisplayHtml, boolean isAutoSelectEnabled, SuggestBox.SuggestionCallback callback) {
super.showSuggestions(box, suggestions, isDisplayHtml, isAutoSelectEnabled, callback);
fireValueChangeEventWithFirstSuggestion(suggestions);
}
}
This idea feels a little muddled to me, so I hope you can find a solution just using event handlers.

Categories