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
Related
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.
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?)
my name is Javier, from Spain
At first, apologize for my inexperience, and for my english :)
This is question anyway:
I'm looking for getting a button state in Apache Pivot. I've tried with many listeners, without result. I don't find any property as "state", "value" or similar.
The closest thing I've found is:
//Intercepta los eventos de toggleButton
BotonGenerico.getButtonStateListeners() .add(new ButtonStateListener() {
#Override
public void stateChanged(Button button, State previousState) {
System.out.println("Changed!");
}
});
But doesn't seem working.
Thanks
I'm going to answer myself, after researching the issue, if anyone is interested:
In Apache Pivot there is no control called "toggle button" as such. Instead of this, i can use the control called "button".
In my case, "BotonGenerico" can transformed in ToggleButton, only changing the toggleButton property via setToggleButton:
BotonGenerico.setToggleButton(true);
After this, I can view or change it state, via getState and setState:
BotonGenerico.setState(State.SELECTED);
BotonGenerico.getState();
//State can be State.SELECTED, State.UNSELECTED or State.MIXED
On many cases, we have to work with 'components', instead 'pushbuttons' (p.e. in some events as mouseMove, mouseOut. focusedChanged...). Casting that mentioned 'component' to button, is simply to manipulate.
Sample:
//Changes PushButton background color when focus changed
#Override
public void focusedChanged(Component component, Component obverseComponent) {
//casting component and obverseComponent in order to convert it in PushButtons
PushButton botonComponent=(PushButton) component;
PushButton botonObverseComponent=(PushButton) obverseComponent;
if (botonComponent.isToggleButton()) {
if (botonComponent.getState() != State.SELECTED) {
System.out.println("Selected");
botonComponent.getStyles().put("backgroundColor", #000000);
}
}
}
Hope this helps.
The content of the tab is formed and displayed when the application is loaded. Later the content of the tab may be changed by other actions. I want to show the newer content after each action. And each time when I click the tab sheet, the content should be refresh/updated. But I failed.
//the content of the tab from the "reprintsTab" class
//in the "reprintsTab" it query data from database and print out
//later I update the data in the database from somewhere else, and I want the tab shows the new content
//I want to click the tab sheet to reload the "reprintTab" class and print out the new content
//here is what I did:
public TabSheet sheet;
//add tab and add the content from "reprintTab" into this tab
sheet.addTab(new reprintsTab());
//add the listener
sheet.addListener(new TabSheet.SelectedTabChangeListener() {
#Override
public void selectedTabChange(SelectedTabChangeEvent event) {
//I know it does not work, because it only reload the class. but not put the content under the tab I want
new reprintsTab();
}
});
What should I do? please help me, thanks.
You can use TabSheet.replaceComponent method to do this:
//Field to store current component
private reprintsTab currentComponent;
//during initialization
currentComponent = new reprintsTab();
sheet.addTab(currentComponent);
sheet.addListener(new TabSheet.SelectedTabChangeListener() {
#Override
public void selectedTabChange(SelectedTabChangeEvent event) {
reprintsTab newComponent = new reprintsTab();
sheet.replaceComponent(currentComponent, newComponent);
currentComponent = newComponent;
}
});
Also, you might want to reload this tab only when it's shown:
sheet.addListener(new TabSheet.SelectedTabChangeListener() {
#Override
public void selectedTabChange(SelectedTabChangeEvent event) {
if (event.getTabSheet().getSelectedTab() == currentComponent) {
//here goes the code
}
}
});
This should work for you, but I would suggest a cleaner approach: implement reprintsTab as a container for components, create method reload or buildInterface method to refresh its' state, so you can just call:
currentComponent.reload();
when you need to update interface.
Also, I hope reprintsTab is just an example name, java class names starting with lowercase letter look ugly.
I have a :
Client Class
ListView
TextField
I need to populate my ListView in order to form a table:
WORKING CODE:
clientModel = new LoadableDetachableModel() {
#Override
protected Object load() {
return Client.getClientListByCompanyName(searchClientInput.getValue());
}
};
searchClientInput.setModel(new Model<String>());
searchClientInput.add(new AjaxFormComponentUpdatingBehavior("onkeyup") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(clientListViewContainer);
}
});
clientListView = new ListView<Client>(CLIENT_ROW_LIST_ID, clientModel) {
#Override
protected void populateItem(ListItem<Client> item) {
Client client = item.getModelObject();
item.add(new Label(CLIENT_ROW_COMPANY_CNPJ_ID, client.getCompanyName()));
item.add(new Label(CLIENT_ROW_COMPANY_NAME_ID, client.getCompanyCnpj()));
}
};
clientListViewContainer.setOutputMarkupId(true);
clientListViewContainer.add(clientListView);
add(clientListViewContainer);
Now, in my HTML, I have a TextField. Whenever an user types something in this TextField, a select will be made in the database with whatever he typed. So for each word, a select is made, and the table needs to be updated. I am guessing I will need to use AJAX and possibly a Model. I'm kind of lost about how I can do this, if someone can provide me examples I would be very grateful.
EDIT: New code that is throwing exception: Last cause: Attempt to set model object on null model of component: searchClientForm:searchClientInput
EDIT 2: Ok so the exception was that my TextField didn't had a model to bind data to. So what I did was: searchClientInput.setModel(new Model<String>());
I also had a problem with the event. Using onkeydown was working, but not as intended. I had Company Name 1-4. If I typed Company Name 1, I would need to press one key again so the table would get updated. With onkeyup this don't happens. Thanks for the help.
You could give the ListView a LoadableDetachableModel which provides the selected clients matching your TextField's value.
Use an AjaxFormComponentUpdatingBehavior on your TextField which add a parent of the ListView to the request target (don't forget #setOutputMarkupId().
I believe the best way to perform what you want (which is repainting a table/list at each input change --> DB access) is with a DataView and a DataProvider.
A DataView is just like the ListView component except it uses an IDataProvider to get the data you want to present. You are able to implement the DataProvider so it accesses your DB, and you can add restrictions (where clauses) to the DataProvider.
[this is more like pseudo-code]
public final class MyDataProvider<T> extends SortableDataProvider<T> {
// ...
Set filters;
// filters is the set where the restrictions you want to apply are stored
...
#Override
public Iterator<T> iterator(int first, int count) {
// DAO (Data Access Object) access to DB
// ...
return dao.findByRestrictions(filters).iterator();
}
...
}
Now on the ajax event on your input component you are able to update the filter being used in the DataProvider, and in the the next repaint of the DataView, the provider will "pull" the data matching the restrictions defined in the filter.
Hope it helps. Best regards.