I am new at Scout and I would like to add Mouse Listener to Button, so I can implement right click on button.
I knew that there is MouseListener object :
MouseListener mouseListener = new MouseListener() {
#Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
#Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
#Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
#Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
#Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
};
but how to add it to a button?
I find function
addButtonListener(listener);
but mouselistener is not class of button listener (But both are extended from EventListener)
An important concept behind Eclipse Scout is the separation of UI and GUI. You do not program against a GUI-Library like SWT, but you define forms containing fields. This represents a kind of model of your application. This model is rendered with different technologies (SWT, Swing, and Eclipse RAP to create web application).
The price of this approach is that the model layer does not have as much possibilities as what is offered by each Graphical Library. The model layer focusses on what is necessary for business application (typically form based).
This is why you won’t be able to register a SWT or a Swing MouseListener directly to the Scout model. If you really need to go in this direction, extending the Scout Model might be a good approach. (See this recent example: Scout tables with fixed columns, it concerns the web-ui domain)
The advantage of this approach is that you do not need to rewrite your application when the underlying technologies changes (Graphical Library, Eclipse Platform…). This matters when you are working on applications that have a long lifecycle (like 10+ years).
Duplicate post on the Scout Forum
Related
When I try to create a new object at clicking a button, the created object does not look okay.
This is what I do:
#UiHandler("button")
protected void onButtonClick(ClickEvent e) {
RootPanel.get().clear();
RootPanel.get().add(new UserLandingPage());
}
The GWT way of switching from a set of widgets to a totally different one is through Activities and Places.
All you need is to follow the google examples on how use the MVP framework.
I collected some demos at the repo below, if you have any doubt don't hesitate to comment and ask further:
https://github.com/jimmyfm/gwt-mvp-examples
Another solution may be to put an HTMLPanel in the root and then switch widgets inside the HTMLPanel by calling
addAndReplaceElement
I want to create a GWT UI where I basically will have a single HTML page that loads a PanelA object. The user will then do their thing and eventually perform an action that will move them onto another view/screen.
I have simplified my existing views to contain just a single button which moves the user onto the next page etc. for simplicity I only have 2 views to start.
Here is my start up entry point.
public class StockWatcher implements EntryPoint
{
public void onModuleLoad()
{
final RootPanel rootPanel = RootPanel.get();
rootPanel.add( PanelA.getInstance() );
}
}
Here is the PanelA class
public class PanelA extends HTMLPanel
{
private static PanelA panel;
private PanelA()
{
super("Panel A");
final RootPanel rootPanel = RootPanel.get();
Button btnNewButton = new Button("Go to panel B");
btnNewButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
rootPanel.clear();
rootPanel.add( PanelB.getInstance() );
}
});
add(btnNewButton);
}
public static PanelA getInstance()
{
if (panel == null)
{
panel = new PanelA();
}
return panel;
}
}
My other PanelB class is pretty much the same as PanelA , ie button that brings me back to PanelA
My UI works as desired.
My Question is, Is this singleton type pattern a correct or proper way to do this? ie Have a stack of Singleton UI views that get popped on/off the main panel?
Also, what is the best way to handle hitory/breadcrumb trace through a GWT app, ie allowing a user to go back to the previous screen bearing in mind that they may navigate to PanelX from either of PanelA, PanelB or PanelC
I use "Activities and Places" to manage all of this, and it's been working quite well in production for a year or so.
https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
I think it's fine to use a Singleton mechanism for your views, but you have to make sure to completely reset any state you store. For me, it was easier to just create new views every time the user navigates to a new spot, and then if I detected a problem with load times or something to retroactively cause the view to re-use its components. I'd advise you to get the navigation working first, and then worry about the singleton (or not) optimizations.
I recommend Activities and Places design pattern.
It covers all the issues you raise in your question, plus many more that you have not thought of (or did not ask about) yet, like native browser history management and ability to bookmark different places within the app, handling of page reloads, efficient memory management vs optimized DOM operations, scalability (building an app with dozens/hundreds of views with minimal code duplication), testability, and code-splitting (where to split large apps).
I suggest you refer "GWTP" framework to make a GWT Project, some of the features currently supported by GWTP:
Dependency injection through GIN and Guice;
Simple but powerful history management mechanism;
Support for nested presenters;
Lazy instantiation for presenter and view;
Effortless and efficient code splitting;
Integrated command pattern supporting undo/redo;
So your questions and query like Singleton UI views, best way to handle hitory/breadcrumb trace and singleton type pattern , will cover and one good framework will make easy project management.
I'm trying to adapt my GWT web application from my home-grown MVC to GWT Platform.
I've managed to port the my application views with presenters, and essentially able to access views via PlaceRequest. And with changing the URL (#).
However I am not sure how to deal with Models using this GWT platform, in the common MVP I know there is a go() method in the presenter which fetches data, say from server via RPC.
In the GWT platform presenter here are the methods automatically generated by the Eclipse plugin:
Constructor
revealInParent
onBind
onReset
Where should I put the RPC code that will fetch and update my model. Say in the presenter I have:
ProfilePresenter.java:
public class ProfilePresenter
extends
Presenter<ProfilePresenter.MyView, ProfilePresenter.MyProxy> {
public interface MyView extends View {
HasText getFullname();
HasText getLocation();
HasText getAboutme();
HasText getLastlogin();
}
private User user; // Model which represents the User information etc.
And when the View associated with the Presenter is shown I need to fetch the User model from the server and update the model and then subsequently update the view through the interfaces it expose.
Also, say I have some buttons in the view, which then can be accessed by the presenter through HasClickHandler where should I put the event handlers?
I would put the RPC call in the onReset method.
See the presenter lifecycle
Personally I deal with events using the reversed MVP pattern. But you can also call a handler this way:
getView().getSubmitButton().addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
}
});
with the following signature for getSubmitButton in your view interface:
HasClickHandlers getSubmitButton()
Sydney covered most of your questions.
In general onResetmethod is a good place to make backend calls.
Sometimes when the backend call takes longer and you want to display the view only after the data was loaded you can use manual reveal.
But for the profile page I don't think that is necessary.
I also agree with the reverse MVP pattern. It's way easer to test presenters using the reverse MVP Pattern than using the HasXXXHandlers interfaces.
I have an ECore model I exploit to automatically generate the model source and JFace edit package. I am trying to develop an alternative view for contents of that model, basically a graph view based on JFreeChart. I have managed to create a JFreeChart based view plugin. Now I need to link the view with the model. How can I do that? I would like to edit the model with the TreeBased editor and see the effects of such editing in the graph view. Is that possible?
thank you
If you open your Graphbased-View ask for the IFile of the current opened editor. After you got the file, you can load the model (see the generated Editor how to load the Model from the underlying resource) attach a IResourceChangeListener to get a notification, if the underlying IFile of your EMF Model changed.
After a notification you can reload the model from your file and show the model in your view.
In addition you have to register a PartListener to get a notification if the user brings another emf-editor to top or he closes the editor (you also have to unload (on close) or refresh (another editor with your emf-model was brought to top).
Yes, it is, as the generated EMF code provides a notification layer: use EObject.eAdapters to add a new adapter, that is notified if the model is changed.
object.eAdapters().add(new Adapter() {
public void setTarget(Notifier newTarget) {
// TODO Auto-generated method stub
}
public void notifyChanged(Notification notification) {
// TODO Auto-generated method stub
}
public boolean isAdapterForType(Object type) {
// TODO Auto-generated method stub
return false;
}
public Notifier getTarget() {
// TODO Auto-generated method stub
return null;
}
});
Ok I have managed to do that following the Zoltán suggestions. Anyway I admit I would have preferred a more structured answer, and that is why I am answering my own question with a brief summary of the solution.
basically the idea is that a view plugin implements the ViewPart interface. Because of this it can actually invoke the following methods
getSite().getWorkbenchWindow().getSelectionService()
in order to get the workbench selection service. You can therefore invoke the SelectionService method
addSelectionListener(ISelectionListener listener)
passing as parameter your own ISelectionListener which can be the same ViewPart you are implementing. You just have to implement the ISelectionListener interface and thus provide an implementation of the selectionChanged method
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection)
how to load the other HTML page when i click a button? i'm using GWT 2.0.3.
p.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
// is there a syntax to load other HTML?
}
});
thanks before, Rafael.
If you use GWT's history mechanism, then you want to look at History.newItem("newPage");
If you want to jump to a totally new URL (and navigate outside your application) then you can use Window.Location.replace("newURL");.
Finally, if you just want to change the page within your application but are not using history, then you probably want to do something like:
RootPanel.get().clear()
RootPanel.get().add( widgetForNewPage );