MessageBox and the return values

11:31 PM / Comments (3) / by Kevin Vu

Good news for me since Peter Liu is looking into my bug :). His knowledge and experience is sure going to help speeding up the progress of this bug :). Anyway, This post is to answer his email and to clear up my first walk through a bit.

My first walk through ends at the saveALl() method which is belong to class: EditorManager.class (package: org.eclipse.ui.internal;)


Method: saveAll()
Package: org.eclipse.ui.internal

// Use a simpler dialog if there's only one
if (modelsToSave.size() == 1) {
Saveable model = (Saveable) modelsToSave.get(0);
String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName());
// Show a dialog.
String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
MessageDialog d = new MessageDialog(
shellProvider.getShell(), WorkbenchMessages.Save_Resource,
null, message, MessageDialog.QUESTION, buttons, 0);


int choice = SaveableHelper.testGetAutomatedResponse();
if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
choice = d.open();
}

// Branch on the user choice.
// The choice id is based on the order of button labels
// above.
switch (choice) {
case ISaveablePart2.YES: // yes
break;
case ISaveablePart2.NO: // no
return true;
default:
case ISaveablePart2.CANCEL: // cancel
return false;
}
}


From the blocks of codes above:
MessageDialog d = new MessageDialog(...);
will define the Save Resource dialog

choice=d.open()
will display the dialog and get the return values when user click YES,NO,or CANCEL.

METHOD THAT DEFINE THE MESSAGEDIALOG:

package org.eclipse.jface.dialogs;
MessageDialog.class


public MessageDialog(Shell parentShell, String dialogTitle,
Image dialogTitleImage, String dialogMessage, int dialogImageType,
String[] dialogButtonLabels, int defaultIndex) {
super(parentShell);
this.title = dialogTitle;
this.titleImage = dialogTitleImage;
this.message = dialogMessage;

switch (dialogImageType) {
case ERROR: {
this.image = getErrorImage();
break;
}
case INFORMATION: {
this.image = getInfoImage();
break;
}
case QUESTION: {
this.image = getQuestionImage();
break;
}
case WARNING: {
this.image = getWarningImage();
break;
}
}
this.buttonLabels = dialogButtonLabels;
this.defaultButtonIndex = defaultIndex;
}


METHOD THAT DISPLAY AND GET THE RETURN VALUE:

package org.eclipse.jface.window;
Window.class

public int open() {

if (shell == null || shell.isDisposed()) {
shell = null;
// create the window
create();
}

// limit the shell size to the display size
constrainShellSize();

// open the window
shell.open();

// run the event loop if specified
if (block) {
runEventLoop(shell);
}

return returnCode;
}

The runEvenLoop(shell) will display and wait until user select one of the button (YES, NO, CANCEL).
The returnCode will return the value that user selected. I tried with YES, NO, CANCEL and the return values are:
YES: returnCode=0
NO: returnCode=1
CANCEL: returnCode=2


GO back to the saveAll() method.

switch (choice) {
case ISaveablePart2.YES: // yes
break;
case ISaveablePart2.NO: // no
return true;
default:
case ISaveablePart2.CANCEL: // cancel
return false;
}

choice will have the return value of open() method above.
If choice=YES, the saveAll() will process on and save all changes (code below), go back out, and server is launched with new configuration.
if choice is NO or CANCEL, saveAll() wont save and just return true or false, go back out, and server is launched with old configuration.


CODES THAT SAVE THE SERVER EDITOR belong to saveAll() method above.

// Create save block.
final List finalModels = modelsToSave;
IRunnableWithProgress progressOp = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
IProgressMonitor monitorWrap = new EventLoopProgressMonitor(
monitor);
monitorWrap.beginTask("", finalModels.size()); //$NON-NLS-1$
for (Iterator i = finalModels.iterator(); i.hasNext();) {
Saveable model = (Saveable) i.next();
// handle case where this model got saved as a result of saving another
if (!model.isDirty()) {
monitor.worked(1);
continue;
}
SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing || confirm);
if (monitorWrap.isCanceled()) {
break;
}
}
monitorWrap.done();
}
};

// Do the save.
return SaveableHelper.runProgressMonitorOperation(
WorkbenchMessages.Save_All, progressOp, runnableContext, shellProvider);

Bug240698: Walkthrough - Part 1

10:35 AM / Comments (1) / by Kevin Vu

BUG SUMMARY:
1/ Add new server
2/ Edit Server
3/ Start Server
4/ "Save Resource" prompts. Select "No".
BUG: "Save Resource" prompts again asking for saving changes again even though selected "No" => Wrong behavior (Supposed to prompt one)

WALKTHROUGH 01
Let start at the point when we start the server and walkthrough to the point of "Save Resource" prompts.

I./ StartAction.java
Class defines methods to start servers

Method: public static void start(IServer server, String launchMode, final Shell shell)
This method is to start the server. So let's set a breakpoint here and step into.


Notice the ServerUIPlugin.saveEditors(). Let's step into this method.

II./ ServerUIPlugin.java
The server UI plugin class

Method: public static boolean saveEditors()

save dirty editors, if applicable
@return boolean - Returns false if the user cancelled the operation



Notice method "saveAllEditors". Let step into this method

III./ Workbench.class
primary responsability is the management of workbench windows, dialogs,
wizards, and other workbench-related windows.

Method: public boolean saveAllEditors(boolean confirm)
is to save all server editors


Notice method "EditorManager.saveAll". Let step into this method.

IV./ EditorManager.class
Manage a group of element editors. Prevent the creation of two editors on the same element.

Method: public static boolean saveAll
Saves the given dirty editors and views, optionally prompting the user.
@return true on success, false if the user canceled the save




Notice the red circle. This is where the first SaveResource dialog prompts for saving changes. User have 3 options:

YES: saveAll() method will process on and save all changes.
NO: saveAll() method will return TRUE
CANCEL: saveAll() method will return FALSE.

Eclipse WTP 3.1M5

10:28 AM / Comments (0) / by Kevin Vu

So I downloaded the lastest stable build of Eclipse WTP, bug240698 is still there (was hoping for a miracle :D). Anyway, let fix the thing! ...

What method is triggerred when select "Start" from server context menu?

9:04 PM / Comments (2) / by Kevin Vu

I'm trying to identify the method that is called when right-click on Tomcat server and select "Start". If anyone come across this method, could you please let me know the name of it? Thanks in advance!

Eclipse Plugin Development

1:21 AM / Comments (1) / by Kevin Vu

I followed Jordan's link on Wiki and find this site: eclipsepluginsite is very helpful to learn developing Eclipse plugins. It provides a hand-on tutorial on how to develop a simple but fully functional eclipse plugin. I've decided to add it in my TODO list for this semester. I properly will take it slow and just do it as a side project beside my bug fix for WTP but will try to manage getting it done by end of this semester. From the first look, the tutorial seems to cover pretty well all the processes from Start (introductions of architectures) to Finish (shipping the plugin as a product) so I think, It will give me a very good fundamental knowledge on developing Eclipse plugins if I go through.

There are 14 chapters in total so the plan is 2 or more chapters per week.

Chapter 01: Introduction to Eclipse Plugin Development
Chapter 02: SWT (Standard Widget Tookit)
Chapter 03: JFace
Chapter 04: Perspectives
Chapter 05: Actions
Chapter 06: Dialogs and Wizards
Chapter 07: Views
Chapter 08: Track Resource Changes
Chapter 09: Preference Pages
Chapter 10: Properties
Chapter 11: Editors
Chapter 12: Builders Natures And Markers
Chapter 13: Help
Chapter 14: Internationalzation

A quick first inspection

2:57 PM / Comments (0) / by Kevin Vu

I'm trying to grab all the classes, methods that are involved in producing the bug. It seems to narrow down to these packages and classes:

package org.eclipse.wst.server.core.internal;
classes:
* ModulePublishInfo.java
Publish information for a specific module on a specific server.
/* Observed: This class could be the center of the investigation since it has the save() and saveResource() methods. */

package rg.eclipse.wst.server.ui.editor;
Classes:
* OverviewEditorPart.java
Server General Editor page. This class extend from ServerEditorPart.

* ServerEditorPart.java
Provide editor page with error messages which will be displayed on the status bar

package org.eclipse.wst.server.ui.internal;
classes:
* Messages.java
Translate messages. This class declares messages.

Checking out and Locating Code for Bug240698

2:14 PM / Comments (0) / by Kevin Vu

The bug that I'm working on is related to the "save resource" dialog when editing server configuration (detail here). I've just located the code related to the bug successfully. Thanks to Mr. Angel Vera for his wonderful presentation and John Dang for his awesome "how to". At first, I missed the step where I actually have to check out the code first before doing the search. How silly was I trying to search without checking out :D. Spending almost 1h pulling my hair trying to figure out how come I got 0 result for all keywords I tried :( :D. Thank John for his how to. I read it again and figured out what I was missing. Anyway, I got the code at hand now. Starting the investigation ;).


The Procedures to locate the code:
1. Identify Bug's component: wst.server

2. Open CVS Repository Exploring Perspective

3. Expands "HEAD" -> Select and check out all items that begin with: org.eclipse.wst.server.* (19 items)

4. Search menu -> choose Search to search for "SaveResource".

5. Double click on the result to view the codes