GWT Auto Refresh Code Jumps To Home Page - java

We want to auto refresh a page that is built using GWT 2. We used a lot of solutions to do it:
GWT auto refresh
automatic refresh of GWT screen
But neither of them worked properly. The problem is a bit complicated:
The auto refresh works in the home page/tab called "Kazalar":
http://dl.dropbox.com/u/103580364/temp/000766.jpg
But if the user is in another tab then after auto refresh the browser jumps to home page/tab:
http://dl.dropbox.com/u/103580364/temp/000767.jpg
In the above question's answer, the answerer says that we should replace the reloadAll() function with code that recreates that part's view (with some Ajax calls to re-fetch data from server if needed). We couldn't test this part because we don't know how to write the code that recreates a specific part's view. Could someone please give an example on how to do it?
public class TimerExample implements EntryPoint, ClickListener {
public void onModuleLoad() {
Button b = new Button("Click and wait 5 minutes");
b.addClickListener(this);
RootPanel.get().add(b);
}
public void onClick(Widget sender) {
Timer t = new Timer
public void run() {
reloadAll();
}
};
// Schedule the timer to run once in 5 minutes.
t.schedule(5*1000*60);
}
private void reloadAll() {
Window.Location.reload();
}
}

Using a timer is fine.
Assuming you know about GWT activities and places.
The harsh way would be to reload the full module using
Window.Location.replace("url#kalazar:");
You already mentionned it; but a really nicer way (assuming you are implemeting the MVP pattern) would be to create a refresh method on the presenter of the Kalazar view. This way you won't need to reload the page.
private void reloadAll() {
myKalazarPresenter.refresh();
}
private void myKalazarPresenter() {
myKalazarView.clear();
myKalazerView.reInit(kalazarInitializationData);
}
Since you say you can't reInit the view, maybe you could just try to delete and recreate it ?

Related

ZK 8.5.0 how to override button widget setLabel function

The ZK setLabel() function of Button widget does not work; when the code runs to the line like foobutton.setLabel(mystring), the button disappears from the browser.
In the eclipse IDE, if I hover on the setLabel() function, the IDE shows this message:
If label is changed, the whole component is invalidate.Thus, you want to smart-update, you have to override this method.
Using ZK 8.5.0
Inside the controller class, I declare:
#Wire
Button delSelectedMonitor;
Inside the controller, I implement a class which implements EventListener:
public class onClickHolderEditMode implements EventListener{
public void onEvent(Event event) throws Exception {
clickedDivEditMode = (Div) event.getTarget();
clickedDivIdEditMode = clickedDivEditMode.getId().split(myUtil.monitorholderString)[1];
String curName = getCamNameById(clickedDivIdEditMode);
delSelectedMonitor.setLabel("DELETE:"+clickedDivIdEditMode+","+curName);
}
}
event binding:
tmpdiv.addEventListener("onClick", new onClickHolderEditMode());
My expectation is that when someone clicks the tmpdiv, the button delSelectedMonitor will change its label according to the property of tmpdiv. However as I say previously, the button is just disappearing.
https://www.zkoss.org/wiki/ZK_Client-side_Reference/General_Control/Widget_Customization
I have tried the section "Specify Your Own Widget Class" at the above website link, but the browser will be pending.
Please help, thank you.
I would prefer a different approach.
Why not use a
<button label="#load(vm.xyz)" ... />
(I wrote using MVVM pattern) and modify variable xyz in clicking action?
Check out http://books.zkoss.org/zk-mvvm-book/8.0/syntax/load.html for implementing guide.

Open JFrame, only after successfull login verification with database. Using Eclipse?

what I'm trying to do is open up a main application from a login screen, only after the login information has been verified in the connected database.
Using Eclipse, what I have so far:
database.java: connection to MS Access Database using UCanAccess. (Success)
login.java: A login window that extends JFrame. When a username and password is entered, it is verified with the database. (Success)
Home.java: The main application window, that I want to only be accessible with a correct username and password. Does not extend JFrame, but has a JFrame within it.
Now, I have been able to set it up so that if the entered username and password are correct, a window pops up saying "Successful login". However, how do I approach setting it up so that after the successful login, it opens up Home.java?
I have looked at:
Open a new JFrame - I have tried the setVisible with my home but Eclipse returns an error saying to create a setVisible method in Home...I thought this is supposed to be an automatic control? After trying to create the method, more issues just arise.
JFrame Open Another JFrame - which suggests adding actionListener and then setting it visible..which I have done: public void actionPerformed(ActionEvent e) {this.setVisible(false); new Home().setVisible(true); but Eclipse just doesn't open up the login window at all. Initially, I thought it could be because my success message is in the actionListener, however even after removing that it still does not work.
Call Jframe from Java class and Open window after button click - My only conclusion is that this is not working since Home.java does not extend JFrame? However, I read through other sources that it is not good to use "extends JFrame"?
I guess I also don't have an understanding of the difference between "extends JFrame" vs a new JFrame within a class? I have been learning java on my own and I'm new to GUI creation. Maybe I am missing something very obvious, but I just can't find a solution.
Any ideas? Thanks
To give an idea, my Home.java starts like this:
public class Home {
private JFrame frame;
private JTable data;
private JTextField Column1;
private JTextField Column2;
private JTable table;
// Launch the application.
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Areas window = new Areas();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
// Create the application.
public Home() {
initialize();
}
//Initialize the contents of the frame.
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 697, 518);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Start by defining a simple work flow which allows you to understand the logical path you want your code to take.
Break down the areas of responsibility so that your objects only do the work that they absolutely have to, for example, your login component should only collect the credentials from the user, it should not be responsible for validating them, that should be the responsibility of some kind of controller.
Equally, neither the login component or it's controller should be responsible for determine what happens after a successful login, that is the responsibility for another controller
This decouples the code and encourages reuse, so the next time you need to present some "login" view, you don't have to recode the whole thing, simply update the controller, model and/or view as required, or re-use it as it is
The concept of a controller in Swing is a little different then a normal MVC implementation, because Swing is already a form of MVC.
What I tend to do instead, is define a contract between the controller and the view which describes what events the view generates (and the events that the controller can expect), for example attemptLogin. This disconnects the controller from the view's implementation, so the view is free to form the view in what ever way it feels like, so long as when it wants to validate the actual credentials it calls attemptLogin
So, you would start with a "main controller" which is responsible for controlling the login and main application controllers. It defines the work flow between the login and the main application and monitors for appropriate events which the controllers may generate to make decisions about what it should do next
A basic flow of operation might look something like
This concept is demonstrated in Java and GUI - Where do ActionListeners belong according to MVC pattern?
Just create a method in your Home class that sets its JFrame to be visible:
public void setJFrameVisible(boolean visible)
{
frame.setVisible(visible);
}
Then, assuming your instance of your Home class is called "home", all you would have to do is:
home.setJFrameVisible(true);
Let me add a bit more context. When you're extending JFrame, the class inherits all the methods/properties of the JFrame class. That's why when you extend JFrame you can just call obj.setVisible(true), because your class inherited the setVisible method from the JFrame class. What you have is a class that contains a JFrame, so you have to call the setVisible method on the internal JFrame, not the class.

What is the proper way to call complex operation from a wizard in Eclipse RCP?

I am trying to initiate complex operation from a wizard.
It includes showing some view and then initiating of this view, which is long.
First way I was just calling view creation code from wizard's performFinish()
But this was not beautiful, since wizard was hanging on pressing Finish button. User would not see that execution began.
Other way I was trying to call Eclipse command from performFinish() and wrote handler to handle this command. I was thinking this will add some asynchronicity.
Unfortunately, I found no way to pass complex objects to a command. Method org.eclipse.core.commands.Command.executeWithChecks(ExecutionEvent) accepts ExecutionEvent, which allows to pass map of parameters, but values should all be of String type. ExecutionEvent is final and I am unable to add by own properties to it.
So what is the proper way to call complex operation from a wizard in Eclipse RCP?
UPDATE
If I am trying to use Job, I am getting org.eclipse.swt.SWTException: Invalid thread access
UPDATE 2
The same is with IRunnableWithProgress.
Probably I need put view initialization into another thread...
As an alternative to using a Job you can also get the wizard to display a progress bar at the bottom of the wizard while your code is running. To do this call
setNeedsProgressMonitor(true);
in the constructor of your Wizard.
In the performFinish use:
getContainer().run(true, true, new WorkClass());
where WorkClass is a class you define which implements IRunnableWithProgress:
class WorkClass implements IRunnableWithProgress
{
#Override
public void run(final IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException
{
// Your work here updating the progress monitor
}
}
Using this code your wizard will remain open showing a progress bar until the work is done. Using a Job the wizard will close and progress will be show in the status line or a pop-up dialog.
In both cases you need to use Display.asycnExec or Display.syncExec to update the UI:
Display.getDefault().asyncExec(new Runnable()
{
#Override
public void run()
{
// Work which updates the UI
}
});
If you have a long-running or complex task to execute at the end of the wizard then it's best to just use the wizard to gather and validate information. On performFinish() you can then use the Eclipse Jobs API to asynchronously execute the task.
Job job = new Job("name") {
#Override
protected IStatus run(IProgressMonitor monitor) {
// TODO Complex task
return Status.OK_STATUS;
}
};
job.schedule();
If you feed progress information back to the IProgressMonitor then the status of the job will be visible in the Eclipse Progress view.
To pass in information from the wizard you can either extend Job with your own class or just have the job code access fields or final variables in the wizard class.

Minimize intro part in eclipse application

I have created my own intro in eclipse application as follows:
public class CustomIntro extends IntroPart {
public void createPartControl(Composite container) {
//add intro, works perfectly fine
}
//override other essential methods
}
The above code works perfectly fine, now I want to minimize this intro programatically. Upon a click of button the intro should be minimized. Actually I want to launch a internal browser upon click of button, and the intro should be minimized and launched internal browser should be visible.
As suggested by #greg-449, I extended the IntroPart than implementing IIntropart. Thanks for that, but my issue still remains. Any help is appreciated.
As #greg-449 pointed, you should extends IntroPart abstract class as is explained in the documentation.
You can use setPartState().
Use this in your IntroPart:
this.getIntroSite().getPage().setPartState(this.getIntroSite().getPage().getActivePartReference(), IWorkbenchPage.STATE_MINIMIZED);

How to add listener to Application Editor in the Eclipse?

I am writing a Eclipse RCP Plug-in for displaying the properties of objects displayed in application editor.
My plug-in extends PageBookView. Every time, i select a new object is opened on the ApplicationEditor(which is Canvas widget),i create a new page & save the old page.
ApplicationEditor extends EditorPart. It fires propertyChange events when the objects (on the active editor changes). All i want is to add listener to applicationEditor. When the required event fires, i have to update my page.
Let me put it in a simmple way.
public Class MyPage implements IPage implements **WHICH_LISTENER**
{
public MyPage(ApplicationEditor editor)
{
this.addPropertyChangeListener(editor);
}
. . . . . .
}
Which Listener should i implement to refresh the page by propertyChange().?
PS: Thanks in advance for your precious advices. Feel free to question me for further clarity in the Question! I cannot change the editor design or code, as i am trying to contribute to an open source project OpenVXML.
Your approach of notifying UI-Elements is not optimal. Your UI-Elements should register listeners to the objects which are changing. The question which listener to implement to the editor depends on which object the editor is listen to. In your case the PageBookView needs a reference to ApplicationEditor to register itself, which is not good, because 1. the PageBookView has an unneccessary dependency to the editor and 2) the editor is not responsible for propagating changes, but the object itself. I would do the following.
Your Editor:
public class MyEditor extends EditorPart implements PropertyChangeListener
public void init(IEditorSite site, IEditorInput input) {
// Getting the input and setting it to the editor
this.object = input.getObject();
// add PropertyChangeListener
this.object.addPropertyChangeListener(this)
}
public void propertyChanged(PropertyChangeEvents) {
// some element of the model has changed. Perform here the UI things to react properly on the change.
}
}
The same thing needs to be done on your pageBook.
public class MyPropertyView extends PageBook implements PropertyChangeListener{
initModel() {
// you have to pass the model from the editor to the depending pageBook.
this.model = getModelFromEditor()
this.object.addPropertyChangeListener(this)
}
public void propertyChanged(PropertyChangeEvents) {
// some element of the model has changed. Perform here the UI things to react properly on the change.
}
}
As you can see both UI Elements are reacting directly to the changes in the model.
Another way of displaying objects in an editor is to use ProperyViews, for an further description see http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html
A time ago, I've written a simple example for all this notification stuff in Eclipse see here.
HTH Tom

Categories