Not able to change Eclipse property view value - java

I am trying to create Eclipse plugin application where on selction of a node in a treeViewer show corresponding value in eclipse property view.
I have implemented the class which overrides IPropertySource interface like below:
public class PropertyViewer implements IPropertySource
{
#Override
public Object getEditableValue()
{
return this;
}
#Override
public IPropertyDescriptor[] getPropertyDescriptors() {
return desc;
}
#Override
public Object getPropertyValue(Object id) {
application specific logic yo return value for a id
}
#Override
public boolean isPropertySet(Object id) {
return true;
}
#Override
public void resetPropertyValue(Object id) {
}
#Override
public void setPropertyValue(Object id, Object value) {
//to set vlaue for a changed property in eclipse property view
}}
Now the problem with above code is that the setPropertyValue is called correctly when the update is done on the eclipse property. but the updated property is not shown inside eclipse property view on enter. But when I deselct and select this node again its showing the updated value. I googled a lot and got the firePropertyChange method have to called under setpropertyValue function. Can anyone help me on this since I am not at all familiar with this. A small code snippet which shows how to call fireproperty change will be help full. Thanks a lot in advance. Tor

Related

Reloading Eclipse view

I have a plugin with a view that creates a tableviewer based on different files found in the selected project (the workspace has more than one project loaded). My problem is that when I try to reload the view the information remains the same as on the first run after Eclipse started.
What should I do in order to reload the content provider everytime I reload the view ?
To be told about which part is active you need to use IPartListener2. Make your ViewPart implement IPartListener2.
Set up the listener in the createPartControl:
#Override
public void createPartControl(final Composite parent)
{
....
getSite().getWorkbenchWindow().getPartService().addPartListener(this);
}
Remove the listener in dispose:
#Override
public void dispose()
{
super.dispose();
...
getSite().getWorkbenchWindow().getPartService().removePartListener(this);
}
You will have to implement the various methods of IPartListener, most of these don't need to do anything, the partVisible method is called when your view (or any other part) is shown:
#Override
public void partVisible(final IWorkbenchPartReference ref)
{
if (ref.getId().equals("your view id"))
{
// Your view has become visible ... add code here to update the table
}
}
This is how my partVisible looks:
public void partVisible(IWorkbenchPartReference partRef) {
// TODO Auto-generated method stub
if (partRef.getId().equals("view id taken from extensions"))
{
getWorkspacePath();
viewer.remove(TableContent.INSTANCE.getRow());
viewer.setInput(TableContent.INSTANCE.updateContentProvider());
viewer.refresh();
}
}
The path is updated (i've displayed the path in the view) but the content of the table isn't....updateContentProvider contains the call of the functions that need to parse some files in the selected project....

Netbeans Custom Component with Custom-Class Property

I have a question about implementing a Swing control which uses a custom class as one of its properties. My goal is to use this control within the netbeans IDE and configure it in design-time like any other component. I already implemented a custom property editor for my ConnectionInfo object which works fine.
However - when I configure my IntLEDs ConnectionInfo property in Netbeans and save it, I can see, in the generated code by Netbeans, that it had troubles to init my ConnectionInfo class.
This is actually what the Netbeans IDE generated:
intLED1.setConnection(???);
So I guess that Netbeans doesn't know how to instantiate my ConnectionInfo class.
But how to tell Netbeans how to do it? :)
This code is basicly a stripped version of my component
public class IntLED extends JPanel {
private ConnectionInfo connection = new ConnectionInfo("", 11159, "", "", Variable.VARIABLE_TYPE.INT);
public IntLED() {
initComponents();
PropertyEditorManager.registerEditor(ConnectionInfo.class, PviCpuPropertyEditor.class);
}
public ConnectionInfo getConnection() {
return connection;
}
public void setConnection(ConnectionInfo connection) {
this.connection = connection;
}
}
Here the ConnectionInfo code. Just some members and Getters/Setters.
public class ConnectionInfo {
private String pviHost = "";
private int pviPort = 11159;
private String pviTask = "";
private String pviVarname = "";
private Variable.VARIABLE_TYPE pviType;
public ConnectionInfo() {
}
public ConnectionInfo(String pviHost, int pviPort, String pviTask, String pviVarname, Variable.VARIABLE_TYPE type) {
this.pviHost = pviHost;
this.pviPort = pviPort;
this.pviTask = pviTask;
this.pviVarname = pviVarname;
this.pviType = type;
}
public String getPviHost() {
return pviHost;
}
public void setPviHost(String pviHost) {
this.pviHost = pviHost;
}
public int getPviPort() {
return pviPort;
}
public void setPviPort(int pviPort) {
this.pviPort = pviPort;
}
public String getPviTask() {
return pviTask;
}
public void setPviTask(String pviTask) {
this.pviTask = pviTask;
}
public String getPviVarname() {
return pviVarname;
}
public void setPviVarname(String pviVarname) {
this.pviVarname = pviVarname;
}
public Variable.VARIABLE_TYPE getPviType() {
return pviType;
}
public void setPviVarname(Variable.VARIABLE_TYPE pviType) {
this.pviType = pviType;
}
}
I also tried to put the members of the ConnectionInfo-Class directly into my IntLED-Class which works fine! But I really need to let the user configure those Members directly in one editor since the editor also provides a tester to test those settings et cetera.
I hope someone can point me to the right direction :)
Thank you very much in advance!
I found the 'missing link' between my Custom Property and the Matisse Code generator!
In my Custom Property Editor (which extends PropertyEditorSupport) I did not override the method getJavaInitializationString().
Apperently when this method is not overwritten, it returns '???' which is exactly what I saw.
Here is how I fixed it:
#Override
public String getJavaInitializationString() {
return String.format("new ConnectionInfo(\"%s\", %d, \"%s\", \"%s\", Variable.VariableType.BOOLEAN)", getValue().getHost(), getValue().getPort(), getValue().getTask(), getValue().getVarname());
}
Surely there should be some Nullpointer checks and so on. But this is basicly how to tell Matisse how to init your Custom Class!
I hope I'm understanding your question, but as I see it you want to be able to add your custom JPanel (IntLED) as a component that you can use in the GUI Editor (Matisse) like every other component?
There is an answer here (https://stackoverflow.com/a/18409887/963076) that explains how to add custom components to the GUI Editor.
EDIT:
Ok, I see. To change the code that Netbeans is generating, you should look for that parameter in the Properties dialog for that component. Right click the component and click "Properties." Then find connection in the list of properties. connection should appear because Netbeans looks for all get() and set() methods and adds them as properties that you can edit. Once you find connection press the ... button to the right. It'll bring up a dialog allowing you to set that component's property. You'll probably need to select "custom code".
(In the pictures below, I used the columnModel property as an illustration).
From the screen below, select "custom code".

FormComponents have common isVisible method

Is there someway i can have several different wicket components have the same implementation of isVisible()
for instance i have Labels, TextFields, DropdownChoices and etc that have the same isVisible method but i dont wont to implement custom classes for all of them since is hard to maintain changes to the code.
btw i can't put them in a webmarkupcontainer due to the design of the page.
I want them all to inherit something like this.
public class DepositoryFormComponent extends Component
{
public DepositoryFormComponent(String id) {
super(id);
}
public DepositoryFormComponent(String id, IModel model) {
super(id, model);
}
public boolean isVisible() {
return isFormDepositoryType();
}
protected boolean isFormDepositoryType() {
return getCurrentSelections().getSelectedOwnedAccount().getAssetType() == AssetType.DEPOSITORY;
}
protected CurrentSelections getCurrentSelections() {
return (CurrentSelections) getSession().getAttribute(CurrentSelections.ATTRIBUTE_NAME);
}
public void onRender(){};
}
You have several options:
If you've got control over the markup, and can group in a single tag all the components you want to control visibility of, you could use a <wicket:enclosure> tag to make a Component control visibility of an entire piece of markup. Notice this won't affect page design, and would achieve a similar effect as to adding a WebMarkupContainer
You could add to those components an IBehavior that will calculate visibility and call setVisible() on the Component. You can also invoke Component#setVisibilityAllowed() if you don't want future calls to setVisible() to alter the Component's visibilty. Maybe not exactly as overriding isVisible, but I think it'll be unlikely to achieve an override if you don't create custom components.
public class VisiblityControlBehavior extends AbstractBehavior {
private boolean isComponentVisible() {
return isFormDepositoryType();
}
protected boolean isFormDepositoryType() {
return getCurrentSelections().getSelectedOwnedAccount().getAssetType() == AssetType.DEPOSITORY;
}
protected CurrentSelections getCurrentSelections() {
return (CurrentSelections) getSession().getAttribute(CurrentSelections.ATTRIBUTE_NAME);
}
#Override
public void bind(Component component) {
boolean visible = isComponentVisible();
component.setVisible(visible);
component.setVisibilityAllowed(visible);
}
}

GWT RootLayoutPanel - Problem rendering page from second to first (first works fine)

Sorry if this was already answered before. I did a little searching and found nothing that could solve my problem. I created an application with Spring Roo, then converted to a GWT app.
All the code generated by Spring Roo is only for CRUD. Now i want to add a Calendar for make appointments, so i need to move to another page.
I´ve added this code to
ScaffoldDesktopShell.java()
public ScaffoldDesktopShell() {
initWidget(BINDER.createAndBindUi(this));
startButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
RootLayoutPanel.get().add(new NovoPainel());
}
});
}
...
Then created a new UIbinder, called it NovoPainel() and added this code:
public NovoPainel() {
initWidget(uiBinder.createAndBindUi(this));
botao.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
RootLayoutPanel.get().clear();
RootLayoutPanel.get().add (new ScaffoldDesktopShell());
}
});
}
Everything goes fine moving from my root panel to NovoPainel, but when i need to go back to rootPanel the page doesn´t render correctly.
EX: Doesn´t show ** ValuePicker ** to click on left panel and render on center.
This is my RootPanel
and this image is when navigate from rootPanel to NovoPainel
and finally this one is returning from NovoPainel to RootPanel
You have to integrate with Roo generated architecture so that you can still benefit from Roo scaffolding.
Roo generated code hides most of behavior in _Roo_Gwt classes and it is because GWT doesn’t currently support ITDs. So changes have to be made in derived classes by overriding methods from _Roo_Gwt class.
To navigate application use Places, ActivityMapper and ActivitiManager (you can find good read on #Thomas Broyer posterous and GWT help).
If you take a look in ScaffoldDesktopShell.ui.xml - page is devided in three main areas.
ApplicationMasterActivities class is responsible for master area.
masterActivityManager.setDisplay(shell.getMasterPanel());
proxyListPlacePicker in ScaffoldDesktopApp.init() generates place change event with apropriate ProxyListPlace.
public void onValueChange(ValueChangeEvent<ProxyListPlace> event) {
placeController.goTo(event.getValue());
}
ApplicationMasterActivities class creates appropriate Activity in Master area by checking EntityProxy type contained in ProxyListPlace object.
public Activity getActivity(Place place) {
if (!(place instanceof ProxyListPlace)) {
return null;
}
ProxyListPlace listPlace = (ProxyListPlace) place;
return new ApplicationEntityTypesProcessor<Activity>() {
#Override
public void handlePet(PetProxy isNull) {
setResult(new PetListActivity(requests, ScaffoldApp.isMobile() ? PetMobileListView.instance() : PetListView.instance(), placeController));
}
#Override
public void handleOwner(OwnerProxy isNull) {
setResult(new OwnerListActivity(requests, ScaffoldApp.isMobile() ? OwnerMobileListView.instance() : OwnerListView.instance(), placeController));
}
}.process(listPlace.getProxyClass());
}
Navigation is created by listing all EntityProxy's in ScaffoldApp class
protected HashSet<ProxyListPlace> getTopPlaces() {
Set<Class<? extends EntityProxy>> types = ApplicationEntityTypesProcessor.getAll();
HashSet<ProxyListPlace> rtn = new HashSet<ProxyListPlace>(types.size());
for (Class<? extends EntityProxy> type : types) {
rtn.add(new ProxyListPlace(type));
}
return rtn;
}
To output meaningfull name in navigation menu they are rendered using ApplicationListPlaceRenderer
public String render(ProxyListPlace object) {
return new ApplicationEntityTypesProcessor<String>() {
#Override
public void handlePet(PetProxy isNull) {
setResult("Pets");
}
#Override
public void handleOwner(OwnerProxy isNull) {
setResult("Owners");
}
}.process(object.getProxyClass());
}
So you have to create new Activity.
public class SomeActivity extends Composite implements Activity{
private static SomeActivityUiBinder uiBinder = GWT
.create(SomeActivityUiBinder.class);
interface SomeActivityUiBinder extends UiBinder<Widget, SomeActivity> {
}
private AcceptsOneWidget display;
public SomeActivity() {
initWidget(uiBinder.createAndBindUi(this));
}
#Override
public String mayStop() {
return null;
}
#Override
public void onCancel() {
onStop();
}
#Override
public void onStop() {
this.display.setWidget(null);
}
#Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
this.display = panel;
this.display.setWidget(this);
}
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>
Hello world!
</g:HTMLPanel>
</ui:UiBinder>
Create appropriate EntityProxy. It is only to obey ProxyListPlace mechanism.
public interface SomeEntityProxy extends EntityProxy {
}
Create SomeActivity in A
#Override
public Activity getActivity(Place place) {
if (!(place instanceof ProxyListPlace)) {
return null;
}
Activity activity = super.getActivity(place);
if (activity == null) {
ProxyListPlace listPlace = (ProxyListPlace) place;
if (SomeEntityProxy.class.equals(listPlace.getProxyClass())) {
activity = new SomeActivity();
}
}
return activity;
}
Add place to navigation in ScaffoldApp or override getTopPlaces in derived class.
rtn.add(new ProxyListPlace(SomeEntityProxy.class));
Set correct menu rendering text in ApplicationListPlaceRenderer
#Override
public String render(ProxyListPlace object) {
String label = super.render(object);
if(label == null) {
if (SomeEntityProxy.class.equals(object.getProxyClass())) {
label = "Some activity";
}
}
return label;
}
Code in GitHub.
GWT 2.1 introduced new classes that implements the Model-View-Places pattern (MVP). This pattern (and the GWT 2.1 concepts) are heavily based on best practices from developers who have build scalable GWT-based applications, so many people are migrating in this direction.
Roo generates a GWT 2.1 application; all of its navigational code is built on top of Activities and Places. The reason I bring this up is it sounds like you are attempting to side-step a lot of this navigational framework to implement your own. I'm not sure, but I believe your problem is coming from the fact that the MVP code is getting confused as a result.
My recommendation would be to work through the GWT MVP article linked above first. Do it completely separate of Roo, because the application that Roo generates is more complex. Once you have a good handle on it, go back through the Roo-generated application and it will likely make more sense.
You can create two div tags in your Porject.html file respectively with id firstdivtag_id1 and seconddivtag_id2.
Display first page by using
RootPanel.get("firstdivtag_id1").add(Panel1);
And then to switch over to another panel use
RootPanel.get("seconddivtag_id2").add(Panel2);

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