Package org.openbp.swing.components.wizard

Examples of org.openbp.swing.components.wizard.SequenceManagerImpl


   * Updates the wizard pages according to the selected generator type.
   */
  public void updateGeneratorPageSequence()
  {
    Generator generator = context.getSelectedGenerator();
    SequenceManagerImpl manager = (SequenceManagerImpl) getManager();

    if (originalSequence == null)
    {
      // First time: Back up the page sequence
      try
      {
        originalSequence = (SequenceManagerImpl) manager.clone();
      }
      catch (CloneNotSupportedException e)
      {
        // Never happens
      }
    }
    else
    {
      // Restore the original page sequence
      try
      {
        String current = manager.getCurrent();

        manager = (SequenceManagerImpl) originalSequence.clone();
        setManager(manager);

        manager.setCurrent(current);
      }
      catch (CloneNotSupportedException e)
      {
        // Never happens
      }
    }

    if (generator != null)
    {
      context.setInvalidGenerator(false);

      // A generator type was selected, we can continue.
      // Perform the necessary preparations
      try
      {
        // Create the generator customizer class for this type
        generator.checkRequirements(context);
        generator.createSettings(context);
        generator.loadSettings(context);

        GeneratorCustomizer customizer = generator.getCustomizer();
        if (customizer != null)
        {
          customizer.beforePageSequenceUpdate(context, this);
        }

        // Create and link the custom pages if defined
        List customPages = generator.getCustomPageList();
        if (customPages != null)
        {
          // Determine the first generator page and its successor
          String currentPageName;
          String next;
          if (getPage(GeneratorWizard.SELECTION_PAGE) != null)
          {
            currentPageName = GeneratorWizard.SELECTION_PAGE;
            next = manager.getNext(currentPageName);
          }
          else
          {
            currentPageName = null;
            next = manager.getFirst();
          }

          // Custom pages, link them into the sequence
          int n = customPages.size();
          for (int i = 0; i < n; ++i)
          {
            GeneratorPageDescriptor pd = (GeneratorPageDescriptor) customPages.get(i);
            String pageName = pd.getName();

            WizardPage page = (WizardPage) getPage(pageName);

            if (page == null)
            {
              // If the page does not yet exist, create it
              String pageClassName = pd.getPageClassName();
              String objectClassName = pd.getObjectClassName();

              if (objectClassName != null)
              {
                // Object page, get/create the object
                Object o = context.getProperty(pageName);
                if (o == null)
                {
                  o = ReflectUtil.instantiate(objectClassName, null,
                    "generator settings object class");
                  context.setProperty(pageName, o);
                }

                // Create property browser page and set the object
                page = new WizardObjectPage(this, pd);
              }
              else if (pageClassName != null)
              {
                try
                {
                  Class pageClass = Class.forName(pageClassName);

                  // We retrieve the Constructor of the page that uses one single parameter
                  // of the type Wizard.

                  Constructor[] ctrs = pageClass.getDeclaredConstructors();
                  for (int ic = 0; ic < ctrs.length; ++ic)
                  {
                    Class[] params = ctrs[ic].getParameterTypes();
                    if (params.length == 1 && params[0] == GeneratorWizard.class)
                    {
                      page = (WizardPage) ctrs[ic].newInstance(new Object[]
                      {
                        this
                      });
                      break;
                    }
                  }

                  if (page == null)
                    throw new GeneratorException("Class '" + pageClassName
                      + "' does not have a (GeneratorWizard) constructor.");
                }
                catch (Exception e)
                {
                  String msg = LogUtil.error(getClass(), "Cannot instantiate page class $0.",
                    pageClassName, e);
                  String exMsg = ExceptionUtil.getNestedMessage(e);
                  throw new GeneratorException(exMsg != null ? exMsg : msg);
                }
              }

              if (page != null)
              {
                // Get the description of the page from the page descriptor
                String pageDescription = pd.getDescription();
                page.setDescription(pageDescription);

                // Add it to the wizard
                addPage(pageName, page);
              }
            }

            if (page != null)
            {
              // Get the title of the page from the page descriptor
              String pageTitle = pd.getDisplayName();
              if (pageTitle == null)
                pageTitle = generator.getDisplayName();
              page.setTitle(pageTitle);

              if (pd.isFinish())
              {
                page.canFinish = true;
              }
            }

            // Link the page
            manager.chain(currentPageName, pageName);
            currentPageName = pageName;
          }

          if (next != null)
          {
            // Link last inserted page with element after selection page
            manager.chain(currentPageName, next);
          }
        }

        if (customizer != null)
        {
View Full Code Here

TOP

Related Classes of org.openbp.swing.components.wizard.SequenceManagerImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.