[jboss-cvs] jbosside/core/plugins/org.jboss.ide.eclipse.firstrun/src/main/org/jboss/ide/eclipse/firstrun/wizard ...

Robert Stryker rawblem at gmail.com
Tue Sep 12 17:25:22 EDT 2006


  User: rawb    
  Date: 06/09/12 17:25:22

  Modified:    core/plugins/org.jboss.ide.eclipse.firstrun/src/main/org/jboss/ide/eclipse/firstrun/wizard 
                        FirstRunWizard.java
  Log:
  Substantial changes, including an extension point, to allow conversion and updates between JBoss IDE versions. Plugins requiring conversions between versions should use this extension point in their own plug-in rather than adding upgrade wizard pages to the firstrun plugin. 
  
  Text for upgrade to 2.0 will need to be decided upon. (Pages created, text is fluff)
  
  Revision  Changes    Path
  1.3       +132 -53   jbosside/core/plugins/org.jboss.ide.eclipse.firstrun/src/main/org/jboss/ide/eclipse/firstrun/wizard/FirstRunWizard.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FirstRunWizard.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/core/plugins/org.jboss.ide.eclipse.firstrun/src/main/org/jboss/ide/eclipse/firstrun/wizard/FirstRunWizard.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- FirstRunWizard.java	29 Jan 2006 04:21:00 -0000	1.2
  +++ FirstRunWizard.java	12 Sep 2006 21:25:22 -0000	1.3
  @@ -21,65 +21,144 @@
    */
   package org.jboss.ide.eclipse.firstrun.wizard;
   
  -import org.eclipse.core.resources.IProject;
  -import org.eclipse.jdt.core.JavaCore;
  +import java.util.ArrayList;
  +import java.util.Collections;
  +import java.util.Comparator;
  +import java.util.Iterator;
  +
  +import org.eclipse.core.runtime.CoreException;
  +import org.eclipse.core.runtime.IConfigurationElement;
  +import org.eclipse.core.runtime.IExtensionRegistry;
  +import org.eclipse.core.runtime.Platform;
   import org.eclipse.jface.wizard.Wizard;
  -import org.jboss.ide.eclipse.firstrun.wizard.pages.FirstRunFinalPage;
  -import org.jboss.ide.eclipse.firstrun.wizard.pages.FirstRunInfoPage;
  -import org.jboss.ide.eclipse.firstrun.wizard.pages.FirstRunPackagingProjectsPage;
  -import org.jboss.ide.eclipse.firstrun.wizard.pages.FirstRunXDocletProjectsPage;
  -import org.jboss.ide.eclipse.packaging.core.PackagingCorePlugin;
  -import org.jboss.ide.eclipse.xdoclet.run.XDocletRunPlugin;
  +import org.jboss.ide.eclipse.core.CorePlugin;
  +import org.jboss.ide.eclipse.firstrun.FirstRunPlugin;
  +import org.jboss.ide.eclipse.firstrun.wizard.pages.AbstractFirstRunPage;
  +
  +public class FirstRunWizard extends Wizard {
  +
  +	private String workspaceLatest;
  +	private FirstRunWizardPageConfigElement[] pageObjects;
  +	
  +	public FirstRunWizard(String workspaceLatest) {
  +		this.workspaceLatest = workspaceLatest;
  +		pageObjects = getExtensions();
  +	}
   
  -public class FirstRunWizard extends Wizard
  -{
  +	public int numPages() {
  +		return pageObjects.length;
  +	}
   
  -   private FirstRunInfoPage page1;
  +   public boolean performFinish() {
  +	   System.out.println(": Performing finish");
  +	   for( int i = 0; i < pageObjects.length; i++ ) {
  +		   pageObjects[i].getPage().performFinish();
  +	   }
  +      return true;
  +   }
   
  -   private FirstRunPackagingProjectsPage page2;
  +   public boolean canFinish() {
  +	   for( int i = 0; i < pageObjects.length; i++ ) {
  +		   if( pageObjects[i].getPage().isPageComplete() == false ) return false;
  +	   }
  +	   return true;
  +   }
   
  -   private FirstRunXDocletProjectsPage page3;
  +   public void addPages() {
  +	   for( int i = 0; i < pageObjects.length; i++ ) {
  +		   AbstractFirstRunPage page = pageObjects[i].getPage();
  +		   page.initialize();
  +		   addPage(page);
  +	   }
  +   }
   
  -   private FirstRunFinalPage page4;
  +   protected FirstRunWizardPageConfigElement[] getExtensions() {
  +		IExtensionRegistry registry = Platform.getExtensionRegistry();
  +		IConfigurationElement[] cf = registry.getConfigurationElementsFor(FirstRunPlugin.PLUGIN_ID, FirstRunPlugin.EXTENSION_WIZARD_PAGE);
  +
  +		ArrayList tmp = new ArrayList();
  +		for( int i = 0; i < cf.length; i++ ) {
  +			FirstRunWizardPageConfigElement frwpce = new FirstRunWizardPageConfigElement(cf[i]);
  +			tmp.add(frwpce);
  +		}
   
  -   public boolean performFinish()
  -   {
   
  -      IProject packagingProjectsToConvert[] = page2.getSelectedProjects();
  -      IProject xdocletProjectsToConvert[] = page3.getSelectedProjects();
  +		// Get rid of any that do not match the current workspace / previous workspace combo
  +		Iterator i = tmp.iterator();
  +		String currentVersion = CorePlugin.getCurrentVersion();
  +		while( i.hasNext()) {
  +			FirstRunWizardPageConfigElement e = (FirstRunWizardPageConfigElement)i.next();
  +			int previousMatch = CorePlugin.compare(workspaceLatest, e.getFromVersion());
  +			int currentMatch = CorePlugin.compare(currentVersion, e.getToVersion());
  +			if( previousMatch != 0 || currentMatch != 0 ) {
  +				i.remove();
  +			}
  +		}
   
  -      for (int i = 0; i < packagingProjectsToConvert.length; i++)
  -      {
  -         PackagingCorePlugin.getDefault().enablePackagingBuilder(JavaCore.create(packagingProjectsToConvert[i]), true);
  +		// Now sort them based on weight
  +		Collections.sort(tmp, new Comparator() {
  +			public int compare(Object o1, Object o2) {
  +				if( o1 instanceof FirstRunWizardPageConfigElement 
  +						&& o2 instanceof FirstRunWizardPageConfigElement ) {
  +					return ((FirstRunWizardPageConfigElement)o1).getWeight() - ((FirstRunWizardPageConfigElement)o2).getWeight();
         }
  +				return 0;
  +			} 
  +		} );
   
  -      for (int i = 0; i < xdocletProjectsToConvert.length; i++)
  -      {
  -         XDocletRunPlugin.getDefault().enableXDocletBuilder(JavaCore.create(xdocletProjectsToConvert[i]), true);
  +	   return (FirstRunWizardPageConfigElement[]) tmp.toArray(new FirstRunWizardPageConfigElement[tmp.size()]);
         }
   
  -      return true;
  +   private class FirstRunWizardPageConfigElement {
  +	   private static final String PAGE_KEY = "WizardPage";
  +	   private static final String FROM_KEY = "fromVersion";
  +	   private static final String TO_KEY = "toVersion";
  +	   private static final String WEIGHT_KEY = "weight";
  +	   
  +	   
  +	   private String fromVersion;
  +	   private String toVersion;
  +	   private int weight;
  +	   private AbstractFirstRunPage page;
  +	   
  +	   private IConfigurationElement element;
  +	   
  +	   public FirstRunWizardPageConfigElement(IConfigurationElement element) {
  +		   this.element = element;
  +		   fromVersion = element.getAttribute(FROM_KEY);
  +		   toVersion = element.getAttribute(TO_KEY);
  +
  +		   try {
  +			   String weightString = element.getAttribute(WEIGHT_KEY);
  +			   if( weightString == null ) weight = 50;
  +			   else weight = Integer.parseInt(element.getAttribute(WEIGHT_KEY));
  +		   } catch( NumberFormatException nfe ) {
  +			   weight = 50;
  +		   }
  +	   }
  +	   
  +	   public AbstractFirstRunPage getPage() {
  +		   if( page == null ) {
  +			   try {
  +			   page = (AbstractFirstRunPage)element.createExecutableExtension(PAGE_KEY);
  +			   } catch( CoreException ce) {
  +				   ce.printStackTrace();
  +			   }
  +		   }
  +		   return page;
  +	   }
  +
  +	public String getFromVersion() {
  +		return fromVersion;
      }
   
  -   public boolean canFinish()
  -   {
  -      if (page4 == null)
  -         return false;
  -
  -      return page4.isPageComplete();
  -   }
  -
  -   public void addPages()
  -   {
  -      page1 = new FirstRunInfoPage();
  -      page2 = new FirstRunPackagingProjectsPage();
  -      page3 = new FirstRunXDocletProjectsPage();
  -      page4 = new FirstRunFinalPage();
  -
  -      addPage(page1);
  -      addPage(page2);
  -      addPage(page3);
  -      addPage(page4);
  +	public String getToVersion() {
  +		return toVersion;
  +	}
  +
  +	public int getWeight() {
  +		return weight;
  +	}
      }
   
   }
  
  
  



More information about the jboss-cvs-commits mailing list