Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * This program is free software; you can redistribute it and/or modify it under the 
   * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software 
   * Foundation.
   *
   * You should have received a copy of the GNU Lesser General Public License along with this 
   * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 
   * or from the Free Software Foundation, Inc., 
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU Lesser General Public License for more details.
  *
  * Copyright 2008 Pentaho Corporation.  All rights reserved.
  *
  * @created Jul 31, 2008 
  * @author wseyler
  */
 package org.pentaho.gwt.widgets.client.wizards;
 
 
 import  com.google.gwt.user.client.ui.Button;
 import  com.google.gwt.user.client.ui.ClickListener;
 import  com.google.gwt.user.client.ui.DeckPanel;
 import  com.google.gwt.user.client.ui.DockPanel;
 import  com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import  com.google.gwt.user.client.ui.HasVerticalAlignment;
 import  com.google.gwt.user.client.ui.HorizontalPanel;
 import  com.google.gwt.user.client.ui.Label;
 import  com.google.gwt.user.client.ui.ListBox;
 import  com.google.gwt.user.client.ui.SimplePanel;
 import  com.google.gwt.user.client.ui.VerticalPanel;
 import  com.google.gwt.user.client.ui.Widget;

Author(s):
wseyler Framework for creating Wizards
 
 @SuppressWarnings("deprecation")
 public abstract class AbstractWizardDialog extends DialogBox implements IWizardPanelListener {
   
   private static final WidgetsLocalizedMessages MSGS = WidgetsLocalizedMessagesSingleton.getInstance().getMessages();
   
   private static final int STEPS_COUNT = 15;  // Defines the height of the steps ListBox
 
   private static final String WIZARD_DECK_PANEL = "pentaho-wizard-deck-panel"//$NON-NLS-1$
 
   private static final String WIZARD_BUTTON_PANEL = "pentaho-wizard-button-panel"//$NON-NLS-1$
 
   // gui elements
   Button backButton = new Button(.back());
   Button nextButton = new Button(.next());
   Button cancelButton = new Button(.cancel());
   Button finishButton = new Button(.finish());
 
   ListBox steps = new ListBox();
   DeckPanel wizardDeckPanel = new DeckPanel();
   VerticalPanel stepsList = new VerticalPanel();
 
   private IWizardPanel[] wizardPanels;
   
   private boolean canceled = false;
   
   public AbstractWizardDialog(String titleIWizardPanel[] panelsboolean autohideboolean modal) {
     super(autohidemodal);
     
     setText(title);
     
     init();
     layout();
     setWizardPanels(panels);
     show();
   }
  
  
Init() Initialize the GUI Elements by setting up the required listeners and state NOTE: This method can be overridden to provided new/additional functionality but should NEVER be called more than once during the lifecycle of the object
 
   protected void init() {
  
     .setStyleName("pentaho-button");
     .setStyleName("pentaho-button");
     .setStyleName("pentaho-button");
     .setStyleName("pentaho-button");
 	  
     .addClickListener(new ClickListener() {
       public void onClick(Widget sender) {
         int oldIndex = .getSelectedIndex();  // The panel currently being displayed
         int newIndex = oldIndex + 1;              // The panel that is going to be displayed
         // Get the actors (next and previous panels)
         IWizardPanel nextPanel = (IWizardPanel).getWidget(newIndex);
        IWizardPanel previousPanel = (IWizardPanel).getWidget(oldIndex);
        if (!onNext(nextPanelpreviousPanel)) {
          return;
        }
        // Update the Listeners
        previousPanel.removeWizardPanelListener(AbstractWizardDialog.this);
        nextPanel.addWizardPanelListener(AbstractWizardDialog.this);
        // Update the GUI with the current widget index;
        updateGUI(newIndex);
      }
    });
    
    .addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        int oldIndex = .getVisibleWidget();
        int newIndex = oldIndex - 1;              // The panel that is going to be displayed  
        // Get the actors (next and previous panels)
        IWizardPanel previousPanel = (IWizardPanel).getWidget(newIndex);
        IWizardPanel currentPanel = (IWizardPanel).getWidget(oldIndex);
        if (!onPrevious(previousPanelcurrentPanel)) {
          return;
        }
        // Update the Listeners
        currentPanel.removeWizardPanelListener(AbstractWizardDialog.this);
        previousPanel.addWizardPanelListener(AbstractWizardDialog.this);
        // Update the GUI with the current widget index;
        updateGUI(newIndex);
      }
    });
    
    .addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
         = true;
        AbstractWizardDialog.this.hide();
      }     
    });
    
    .addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        if (onFinish()) {
          AbstractWizardDialog.this.hide();
        }
      }
    });
    
    .setEnabled(false);
    
  }

  
  

Parameters:
index of the widget that will be shown. updateGUI(int index) sets up the panels and buttons based on the state of the widget (IWizardPanel) that will be shown (index).
  protected void updateGUI(int index) {
    .setVisible(.getWidgetCount() > 1);
    .setVisible(.getWidgetCount() > 1);
    .setVisible(.getWidgetCount() > 1);
    // Updates the selected step
    .setSelectedIndex(index);
    // Shows the current IWizardPanel
    .showWidget(index);
    // Enables the next button if the current IWizardPanel can continue and we're not at the last IWizardPanel
    .setEnabled(((IWizardPanel).getWidget(index)).canContinue() && index < .getWidgetCount() -1);
    // Back button always enabled unless we're on the first IWizardPanel
    .setEnabled(index > 0);
    // Current IWizardPanel can finish at any step.
    .setEnabled(((IWizardPanel).getWidget(index)).canFinish());
    
  }
  
  
layout() Lays out the GUI elements. Should only be called ONCE during the objects lifecycle
  protected void layout() {    
    // Create the overall container to be displayed in the dialog
	  
	SimplePanel deckWrapper = new SimplePanel();
	deckWrapper.setHeight("100%");
	deckWrapper.setWidth("100%");
	deckWrapper.setStyleName("dialog-content");
	  
    DockPanel content = new DockPanel();
    
    // Create the Steps and add it to the content
     = new VerticalPanel();
    .add(new Label(.steps()));
    .setVisibleItemCount();
    .add();
//    steps.setSize("30%", "100%");
    content.add(, DockPanel.WEST);
    
    // Add the wizardPanels to the Deck and add the deck to the content
//    wizardDeckPanel.setSize("70%", "100%");
	deckWrapper.setWidget();
    content.add(deckWrapper, DockPanel.CENTER);
    .addStyleName();
    
    // Add the control buttons
    HorizontalPanel wizardButtonPanel = new HorizontalPanel();
    wizardButtonPanel.setSpacing(2);
    // If we have only one button then we dont need to show the back and next button.
    wizardButtonPanel.add();
    wizardButtonPanel.add();
    wizardButtonPanel.add();
    wizardButtonPanel.add();
    wizardButtonPanel.addStyleName();
    HorizontalPanel wizardButtonPanelWrapper = new HorizontalPanel();
    wizardButtonPanelWrapper.setWidth("100%"); //$NON-NLS-1$
    wizardButtonPanelWrapper.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    wizardButtonPanelWrapper.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
    wizardButtonPanelWrapper.add(wizardButtonPanel);
    
    content.add(wizardButtonPanelWrapper, DockPanel.SOUTH);
    content.setCellVerticalAlignment(wizardButtonPanelWrapper, HasVerticalAlignment.ALIGN_BOTTOM);
    
    // Add the content to the dialog
    add(content);
    content.setWidth("100%"); //$NON-NLS-1$
    content.setHeight("100%"); //$NON-NLS-1$
  }

  

Parameters:
wizardPanels - IWizardPanel[] Creates a wizardDeckPanel with the contents of wizardPanels respecting the order. Creates a step panel populated with the step names from the wizardPanels and then sets the current wizard panel to the first panel in the list and updates the GUI.
  public void setWizardPanels(IWizardPanel[] wizardPanels) {
    this. = wizardPanels;
    
    .clear();      
    .clear();
    if (wizardPanels != null  && wizardPanels.length > 0) { // Add new wizardPanels
      for (IWizardPanel panel : wizardPanels) {
        .addItem(panel.getName());
        .add((Widget) panel);
      }
      
      ((IWizardPanel.getWidget(0)).addWizardPanelListener(this);
      if (wizardPanels.length == 1) { // We only have one item so change the Finish button to ok.
        .setText(.ok());
      }
      
      updateGUI(0);
    }
  }
  
  

Returns:
the current list if IWizardPanel in an array.
  public IWizardPanel[] getWizardPanels() {
    return ;
  }
  
  /* (non-Javadoc)
   * @see org.pentaho.gwt.widgets.client.wizards.IWizardPanelListener#panelChanged(org.pentaho.gwt.widgets.client.wizards.IWizardPanel)
   */
  public void panelUpdated(IWizardPanel wizardPanel) {
    int index = .getVisibleWidget();
    int lastPanelIndex = .getWidgetCount() -1;
    
    .setEnabled(wizardPanel.canContinue() && index < lastPanelIndex);
    .setEnabled(wizardPanel.canFinish());
  }
  
  public boolean wasCancelled() {
    return ;
  }
  
  
abstract onFinish() Override for action to take when user presses the finish button. Return true if the wizard dialog should close after the finish() method completes.
  protected abstract boolean onFinish();
  
  

Parameters:
nextPanel
previousPanel
Returns:
boolean if the "Next" operation should complete. Users should return true if the Wizard should proceed to the next panel. This would be a good spot to retrieve/update state information between the two panels. This method is call before the next method executes (ie. next panel is displayed). If nothing needs to be done simply return true
  protected abstract boolean onNext(IWizardPanel nextPanelIWizardPanel previousPanel);
  
  

Parameters:
previousPanel
currentPanel
Returns:
boolean if the "Back" operation should complete Users should return true if the Wizard should proceed to the next panel. This would be a good spot to retrieve/update state information between the two panels. This method is call before the back method executes (ie. previous panel is displayed). If nothing needs to be done simply return true;
  protected abstract boolean onPrevious(IWizardPanel previousPanelIWizardPanel currentPanel);
New to GrepCode? Check out our FAQ X