Announcement Announcement Module
Collapse
No announcement yet.
AbstractWizardPage, next button and forcing a refresh. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractWizardPage, next button and forcing a refresh.

    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((Componente.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 = (SourceFilePagegetPage("diffWizard.primarySourceFilePage");
            
    SourceFilePage secondary = (SourceFilePagegetPage("diffWizard.secondarySourceFilePage");

            if (
    primary.getSelectedFile() != null
                    
    && secondary.getSelectedFile() != null) {
                return 
    true;
            }

            return 
    false;
        }

        public 
    boolean onFinish() {

            
    File file = ((SourceFilePagegetPage("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(tableMDloadTableMDrpmTableMD);

            
    model.initialize(file);

            
    getActiveWindow().getPage().showView("initialView"model);

            return 
    true;

        }


    Last edited by funks; Sep 17th, 2009, 07:56 PM.

  • #2
    Anybody have any tips?

    Comment


    • #3
      I'll have a look at your examples ASAP

      Comment


      • #4
        Originally posted by LievenDoclo View Post
        I'll have a look at your examples ASAP
        Hi,

        I was able to get it to refresh by doing.

        PHP Code:
        setEnabled(false);
        setEnabled(true); 
        I'm pretty sure that's not the correct way to do it (there's gotta be something better), I wanted to check out the sprint-rcp source (svn - trunk) but I keep on getting

        svn: Can't open file 'spring-richclient-integrations\spring-richclient-jide\spring-richclient-jide-samples\spring-richclient-jide-sample-google\src\main\java\com\jidesoft\spring\richclien t\googledemo\preferences\.svn\tmp\text-base\SettingsDialog.java.svn-base': The system cannot find the path specified.

        Comment

        Working...
        X