Minimize intro part in eclipse application - java

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);

Related

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.

GWT Auto Refresh Code Jumps To Home Page

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 ?

GWT app UI wont display

I have implemented a simple GWT app that uses 1 Place and 1 Activity (which I have implemented as a Presenter which extends an AbstractActivity and which contains a Composite "view" subclass). The 1 and only UI object in the view is a GWT-Bootstrap NavBar that I want presented at the very top of my "home page".
I'm running the app locally from inside Eclipse and am not getting any compiler or runtime errors. When I go to the URL that the Development Mode console points me to, I get a slight pause in the browser (I assume this is the browser "downloading" the JavaScript) and then I see a blank white screen (instead of my NavBar). The window title is correct (I set this in the module's HTML page) and when I view source I see the same HTML source, so I know that the app's JavaScript is getting to the browser properly. It's just not rendering the NavBar.
I have sprinkled System.out.println() statements throughout onModuleLoad(), my default ActivityManager, ActivityMapper, PlaceHistoryMapper, presenter and view Composite, and all these sysout statements print in the dev console; telling me that I have wired everything together correctly, and that at runtime when the PlaceHistoryHandler#handleCurrentHistory method is called (from inside onModuleLoad), I should be seeing my NavBar.
The only possibilities I can think of are:
I have configured gwt-bootstrap incorrectly; or
I'm not using UiBinder correctly
Something else is wrong with how I am using Activities and Places, or perhaps how I am attaching the UI to RootLayoutPanel inside onModuleLoad().
As for gwt-bootstrap:
I placed the JAR on my project's classpath (I know this because when I include a new UiField of type NavBar inside my widget/view, I don't get any compiler errors)
I added <inherits name="com.github.gwtbootstrap.Bootstrap"/> to my GWT module XML
So if there's anything else I have to configure, please let me know!
As for the UiBinder stuff, here's my widget/view:
public class WebRootDisplay extends BaseDisplay {
private static WebRootDisplayUiBinder uiBinder = GWT
.create(WebRootDisplayUiBinder.class);
interface WebRootDisplayUiBinder extends UiBinder<Widget, WebRootDisplay> {
}
#UiField
Navbar navBar;
public WebRootDisplay(EventBus eventBus) {
super(eventBus);
System.out.println("I get this printing to the console at runtime.");
initWidget(uiBinder.createAndBindUi(this));
System.out.println("...and this too!");
}
}
<!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"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<b:Navbar ui:field="navBar">
<b:Nav>
<b:NavLink href="http://www.google.com">
Home
</b:NavLink>
</b:Nav>
</b:Navbar>
</g:HTMLPanel>
</ui:UiBinder>
One thing I noticed is that I've got my NavBar inside an HTMLPanel in the UiBinder XML. I did this because I used the Google-Eclipse plugin to generate a new UiBinder for me (which autogenerated both the Composite (which I then modified to extend BaseDisplay, which itself extends Composite) as well as the UiBinder snippet. I figured GWT wants me to put all the UI fields inside this HTMLPanel...(?)
If I'm missing anything here please let me know. I'm not instantiating the NavBar field because I believe that's what createAndBindUi does for me.
If both my gwt-bootstrap config and my use of UiBinder looks correct, then something else is obviously wrong and I will have to post more code. I just wanted to hold off on that initially before these first two items were ruled out. Thanks in advance!
Update
Here is onModuleLoad:
public void onModuleLoad() {
// Some homegrown DI stuff. I have verified that the injector works properly.
ApplicationScope appScope = new ApplicationScope();
setInjector(new ApplicationInjector(appScope,
InjectorProvider.newMasterProvider()));
// Add the sole composite child to the RootLayoutPanel.
// I have verified that injectWebRootDisplay returns a fully configured
// WebRootDisplay instance.
RootLayoutPanel.get().add(injector.injectWebRootDisplay());
historyHandler.register(placeController, eventBus, defaultPlace);
historyHandler.handleCurrentHistory();
}
Could you paste the onModuleLoad() part of your code please?
If you don't got any Exception and error message, I think you should check that you add the view properly to the RootPanel, or when you run the app you should check that the view is there in a div in the HTML and just unvisible or something similar.
The UiBinder part looks fine in a first look.
EDIT:
This onModuleLoad() doesn't said too much to me, but you could try something.
I always use the RootLayoutPanel.get() method in the following way:
RootLayoutPanel.get("someDivId").add(injector.injectWebRootDisplay());
So I always add a div or table to the placeholder HTML with a id, so you can refer to that div when you get the RootPanel. I'm not confident about this is necessary, but I saw this at the first time, and it's working properly.
If you have question or problem, please let me know. :)
Well, I've tried a local example looking exactly like yours code, and I think that problem is not in UI binder. The code you provided so far, is correct, so it most likely that the error is somewhere else.
The biggest suspect is the BaseDisplay class. As far as I can see, this class is not from GWT or gwt-bootstrap. You can really quickly check it, by changing WebRootDisplay class, so it extends classic GWT Composite class instead of BaseDisplay (and disabling all mvp stuff for while). If it works, you have a proof that the problem is caused by 'BaseDisplay'
Since I don't have the full code, I can only assume that WebRootDisplay is used also for displaying the views, and most likely the error is that when view is added to that class, previously added widget (in your case it is a NavBar which you add in constructor of WebRootDisplay) is removed. Most likely the problem should be in methods setWidget and initWidget
In my experience with GWT Activities and Places, a common culprit of a blank white page is failing to register the Place's Tokenizer with the PlaceHistoryMapper as so:
/**
* PlaceHistoryMapper interface is used to attach all places which the
* PlaceHistoryHandler should be aware of. This is done via the #WithTokenizers
* annotation or by extending PlaceHistoryMapperWithFactory and creating a
* separate TokenizerFactory.
*/
#WithTokenizers({
MyPlace.Tokenizer.class,
SomeOtherPlace.Tokenizer.class})
public interface AppPlaceHistoryMapper extends PlaceHistoryMapper {}
See https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces#PlaceHistoryMapper
Another cause for a white page (particularly when using RootLayoutPanel.get() with a single place is failing to map the place correctly in the ActivityMapper:
/**
* AppActivityMapper associates each Place with its corresponding
* {#link Activity}
*
* #param clientFactory
* Factory to be passed to activities
*/
public class AppActivityMapper implements ActivityMapper {
private ClientFactory clientFactory;
public AppActivityMapper(ClientFactory clientFactory) {
super();
this.clientFactory = clientFactory;
}
#Override
public Activity getActivity(Place place) {
if (place instanceof MyPlace)
return new MyActivity((MyPlace) place, clientFactory);
else if (place instanceof SomeOtherPlace)
return new SomeOtherActivity((SomeOtherPlace) place, clientFactory);
return null; // If your return null with single place bound to RootLayoutPanel
// you may get a blank white page
}
}
See https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces#ActivityMapper
Without a more complete code sample it is impossible to determine exactly what is happening, but the two causes outlined above are common oversights which may help anyone who comes across this thread.
Instead of System.println use GWT.log messages. Then open the Javascript console (of Firebug or Chrome) and see where your code ends up. GWT.log will print out in the browser console, so you can see what the compiled JS code does.
Also, if you compile with the Pretty mode, you'll see the generated Javascript code in the browser and be able to step through and see what is being called (or not).

Window closing in Swing Application Framework

I am using Swing Application Framework JSR(296) for my Swing based Java application.
Similar to AboutBox, I have followed the usage of #Action and added some JDialog classes to my project.
The problem is, when I close the main frame, my application still runs in background.
To overcome this I added following code to the configureWindow() of my main application class:
protected void configureWindow(java.awt.Window root) {
root.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent e) {
// write your code here
Application.getInstance(MyApp.class).exit();
}
});
}
But with this modification whenever I close the the dialog (including AboutBox), it also closes the main frame.
What should I do to prevent the entire application from exiting and just close the dialog box?
Update:
I am using NetBeans IDE 7.01 which allows to create Swing Application Framework project.
It generates a project skeleton as shown below:
MyApp
|--myapp
| |--MyApp.java
| |--MyAppAboutBox.java
| |--MyAppView.java
|
|--myapp.resources
|--MyApp.properties
|--MyAppAboutBox.properties
|--MyAppView.properties
NetBeans IDE allows to add actions from Window->Properties menu.
MyApp class extends org.jdesktop.application.SingleFrameApplication which is my main class.
MyAppView extends FrameView which is my main view.
Implementation classes of javax.swing.JDialog are in the myapp.view package.
The WindowEvent class has a method call getWindow(), which returns the window that is closing.
Inside your windowClosing method you can check: if the window is the main application window, use the code that you currently have. If it is not, just call Window.dispose()
Edit: I didn't notice that you were creating custom dialogs in your application. Maybe you forget to dispose them? You should add code like the one in the auto generated about box:
#Action public void closeAboutBox() {
dispose();
}
and call this action whenever the dialog closes. If this is not the problem, a thread dump will probably help you in order to find out which thread is running when you close the main window.
I think what you are actually looking for is setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);. Have a look at the JavaDoc API...

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