Hello,
I'm using Spring RCP 1.1 along with the Abstract Wizard and the Abstract Wizard Page.
I'm trying to prevent the Next button from being enabled until the user selects a file in the current WizardPage (in other words, don't allow the user to continue to the next wizard page until the file is chosen). One is supposed to override the "canFlipToNextPage" method in order to indicate if the next button is enabled. My ActionListener is supposed to set the "selectedFile" hence the next call to "canFlipToNextPage" should return true.
How do I force the current wizard page to redraw itself from my actionPerformed method, so that the "next" button will be enabled?
Thanks
PHP Code:
package com.theintegrationzone.ecudiff.ui.wizard;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import org.springframework.binding.validation.support.DefaultValidationMessage;
import org.springframework.richclient.core.Severity;
import org.springframework.richclient.dialog.MessageDialog;
import org.springframework.richclient.wizard.AbstractWizard;
import org.springframework.richclient.wizard.AbstractWizardPage;
import org.springframework.util.Assert;
import com.theintegrationzone.ecudiff.domain.Scaling;
import com.theintegrationzone.ecudiff.domain.ThreeDTable;
import com.theintegrationzone.ecudiff.domain.ThreeDTableMetaData;
import com.theintegrationzone.ecudiff.domain.TwoDTableMetaData;
import com.theintegrationzone.ecudiff.ui.SimpleFileFilter;
public class DiffWizard extends AbstractWizard {
private final class SourceFilePage extends AbstractWizardPage implements
ActionListener {
private JFileChooser chooser;
private File selectedFile;
protected SourceFilePage(String pageId) {
super(pageId);
}
public void actionPerformed(ActionEvent e) {
int returnVal = chooser.showOpenDialog((Component) e.getSource());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File aFile = chooser.getSelectedFile();
Assert.notNull(aFile);
currentDirectory = aFile.getParentFile();
if (aFile != null) {
selectedFile = aFile;
/*
* this is ugly - I have to read the RCP source to find a
* better method to force a redraw. But for now, toggling
* enable fires some sort of event
*/
setEnabled(false);
setEnabled(true);
} else {
MessageDialog invalidMessage = new MessageDialog(
getMessage("diffWizard.sourceFilePage.invalidROMImageDialog.label"),
new DefaultValidationMessage(
null,
Severity.WARNING,
getMessage("diffWizard.sourceFilePage.invalidROMImageDialog.message")));
invalidMessage.showDialog();
}
}
}
public boolean canFlipToNextPage() {
boolean canFlip = false;
if (getNextPage() != null && selectedFile != null) {
canFlip = true;
}
return canFlip;
}
protected JComponent createControl() {
chooser = new JFileChooser();
SimpleFileFilter filter = new SimpleFileFilter();
filter.addExtension("hex");
filter.setDescription("ECU Flash ROM Image");
chooser.setFileFilter(filter);
final JPanel panel = getComponentFactory().createPanel();
final JButton button = getComponentFactory().createButton(
getMessage("diffWizard.sourceFilePage.openRomImage"));
button.addActionListener(this);
panel.add(button);
return panel;
}
public File getSelectedFile() {
return selectedFile;
}
public void onAboutToShow() {
if (currentDirectory != null) {
chooser.setCurrentDirectory(currentDirectory);
}
}
}
private File currentDirectory;
public void addPages() {
addPage(new SourceFilePage("diffWizard.primarySourceFilePage"));
addPage(new SourceFilePage("diffWizard.secondarySourceFilePage"));
}
public boolean canFinish() {
SourceFilePage primary = (SourceFilePage) getPage("diffWizard.primarySourceFilePage");
SourceFilePage secondary = (SourceFilePage) getPage("diffWizard.secondarySourceFilePage");
if (primary.getSelectedFile() != null
&& secondary.getSelectedFile() != null) {
return true;
}
return false;
}
public boolean onFinish() {
File file = ((SourceFilePage) getPage("diffWizard.primarySourceFilePage"))
.getSelectedFile();
Scaling afrScaling = new Scaling("AFR").setEndian("big")
.setStorageType("uint8").setFormat("%.1f").setToExpression(
"14.7*128/x");
Scaling loadScaling = new Scaling("Load").setEndian("big")
.setStorageType("uint16").setFormat("%.0f").setToExpression(
"x*10/32");
Scaling rpmScaling = new Scaling("RPM").setEndian("big")
.setStorageType("uint16").setFormat("%.0f").setToExpression(
"x*1000/256");
TwoDTableMetaData loadTableMD = new TwoDTableMetaData("Load")
.setAddress(397052l).setScaling(loadScaling)
.setElementsSize(21);
TwoDTableMetaData rpmTableMD = new TwoDTableMetaData("RPM").setAddress(
397014l).setScaling(rpmScaling).setElementsSize(16);
ThreeDTableMetaData tableMD = new ThreeDTableMetaData(
"High Octane Fuel Map").setAddress(348199l).setSwapXY(true)
.setScaling(afrScaling);
ThreeDTable model = new ThreeDTable(tableMD, loadTableMD, rpmTableMD);
model.initialize(file);
getActiveWindow().getPage().showView("initialView", model);
return true;
}
}