[jboss-cvs] jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/wizards ...

Robert Stryker rob.stryker at jboss.com
Mon Apr 16 13:56:54 EDT 2007


  User: rawb    
  Date: 07/04/16 13:56:54

  Added:       core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/wizards     
                        AbstractPackageWizard.java
                        WizardPageWithNotification.java NewJARWizard.java
                        WizardWithNotification.java FilesetWizard.java
  Log:
  Complete rewrite of the the two plugins leading to a cleaner, leaner project. 
  
  Revision  Changes    Path
  1.12      +21 -30    jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/wizards/AbstractPackageWizard.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AbstractPackageWizard.java
  ===================================================================
  RCS file: AbstractPackageWizard.java
  diff -N AbstractPackageWizard.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ AbstractPackageWizard.java	16 Apr 2007 17:56:54 -0000	1.12
  @@ -0,0 +1,158 @@
  +package org.jboss.ide.eclipse.packages.ui.wizards;
  +
  +import java.lang.reflect.InvocationTargetException;
  +
  +import org.eclipse.core.resources.IContainer;
  +import org.eclipse.core.resources.IProject;
  +import org.eclipse.core.runtime.IProgressMonitor;
  +import org.eclipse.jface.operation.IRunnableWithProgress;
  +import org.eclipse.jface.resource.ImageDescriptor;
  +import org.eclipse.jface.viewers.IStructuredSelection;
  +import org.eclipse.jface.wizard.IWizardPage;
  +import org.eclipse.jface.wizard.WizardPage;
  +import org.eclipse.ui.INewWizard;
  +import org.eclipse.ui.IWorkbench;
  +import org.jboss.ide.eclipse.packages.core.Trace;
  +import org.jboss.ide.eclipse.packages.core.model.IPackage;
  +import org.jboss.ide.eclipse.packages.core.model.IPackageNode;
  +import org.jboss.ide.eclipse.packages.core.model.internal.PackagesModel;
  +import org.jboss.ide.eclipse.packages.ui.views.ProjectPackagesView;
  +import org.jboss.ide.eclipse.packages.ui.wizards.pages.PackageInfoWizardPage;
  +
  +public abstract class AbstractPackageWizard extends WizardWithNotification implements INewWizard {
  +	private PackageInfoWizardPage firstPage;
  +	private WizardPage pages[];
  +	protected IProject project;
  +	protected Object selectedDestination;
  +	protected IPackage existingPackage;
  +	
  +	public AbstractPackageWizard () {	
  +		this.project = ProjectPackagesView.getInstance().getCurrentProject();
  +	}
  +	
  +	public AbstractPackageWizard (IPackage existingPackage) {
  +		this.existingPackage = existingPackage;
  +		this.project = existingPackage.getProject();
  +	}
  +	
  +	public void addPages() {
  +		firstPage = new PackageInfoWizardPage(this, existingPackage);
  +		addPage(firstPage);
  +		
  +		pages = createWizardPages();
  +		for (int i = 0; i < pages.length; i++) {
  +			addPage(pages[i]);
  +		}
  +	}
  +	
  +	public boolean canFinish() {
  +		if (firstPage.isPageComplete()) {
  +			for (int i = 0; i < pages.length; i++) {
  +				if (!pages[i].isPageComplete()) return false;
  +			}
  +			return true;
  +		}
  +		
  +		return false;
  +	}
  +	
  +	public boolean performFinish() {
  +		IWizardPage currentPage = getContainer().getCurrentPage();
  +		
  +		if (currentPage instanceof WizardPageWithNotification) {
  +			((WizardPageWithNotification)currentPage).pageExited(WizardWithNotification.FINISH);
  +		}
  +		
  +		final boolean create = this.existingPackage == null;
  +		final IPackage pkg = firstPage.getPackage();
  +		final Object destination = firstPage.getPackageDestination();
  +		
  +		boolean performed = performFinish(pkg);
  +		
  +		if (performed) {
  +			try {
  +				getContainer().run(false, false, new IRunnableWithProgress () {
  +					public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
  +						IPackageNode parent = null;
  +						
  +						if (destination instanceof IPackageNode) {
  +							// if we're modifying an existing package, remove old parentage
  +							if (!create && !destination.equals(pkg.getParent())) {
  +								if (pkg.getParent() != null) {
  +									pkg.getParent().removeChild(pkg);
  +								}
  +							}
  +							parent = (IPackageNode)destination;
  +						} else {
  +							parent = PackagesModel.instance().getRoot(project, true, monitor);
  +						}
  +						
  +						if( create ) 
  +							PackagesModel.instance().attach(parent, pkg, monitor);
  +						else
  +							PackagesModel.instance().saveModel(project, monitor);
  +					}
  +				});
  +			} catch (InvocationTargetException e) {
  +				Trace.trace(getClass(), e);
  +			} catch (InterruptedException e) {
  +				Trace.trace(getClass(), e);
  +			}
  +		}
  +		return performed;
  +	}
  +
  +	public void init(IWorkbench workbench, IStructuredSelection selection) {
  +		if (selection == null) return;
  +		project = ProjectPackagesView.getInstance().getCurrentProject();
  +		Object selected;
  +		
  +		if( selection.isEmpty() ) {
  +			selected = project;
  +		} else {
  +			selected = selection.getFirstElement();
  +		}
  +
  +		if (selected instanceof IPackageNode)
  +		{
  +			IPackageNode node = (IPackageNode) selected;
  +			if (node.getNodeType() == IPackageNode.TYPE_PACKAGE || node.getNodeType() == IPackageNode.TYPE_PACKAGE_FOLDER)
  +			{
  +				selectedDestination = selected;
  +			}
  +			project = node.getProject();
  +		}
  +		else if (selected instanceof IContainer)
  +		{
  +			selectedDestination = selected;
  +		}
  +		else {
  +			selectedDestination = project;
  +		}
  +		
  +		setNeedsProgressMonitor(true);
  +	}
  +	
  +	public Object getSelectedDestination ()
  +	{
  +		return selectedDestination;
  +	}
  +	
  +	public abstract boolean performFinish(IPackage pkg);
  +	public abstract WizardPage[] createWizardPages();
  +	public abstract ImageDescriptor getImageDescriptor();
  +	public abstract String getPackageExtension();
  +	
  +	public IProject getProject() {
  +		return project;
  +	}
  +	
  +	/**
  +	 * Returns the package created by this wizard.
  +	 * Note: This should only be called after the first page has been completed
  +	 * @return The package
  +	 */
  +	public IPackage getPackage () {
  +		return firstPage.getPackage();
  +	}
  +}
  
  
  
  1.1      date: 2007/04/16 17:56:54;  author: rawb;  state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/wizards/WizardPageWithNotification.java
  
  Index: WizardPageWithNotification.java
  ===================================================================
  /**
   * JBoss, a Division of Red Hat
   * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
  * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software 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.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.ide.eclipse.packages.ui.wizards;
  
  import org.eclipse.jface.resource.ImageDescriptor;
  import org.eclipse.jface.wizard.IWizardPage;
  import org.eclipse.jface.wizard.WizardPage;
  
  /**
   *
   * @author rob.stryker at jboss.com
   */
  public abstract class WizardPageWithNotification extends WizardPage implements IWizardPage {
  	/**
  	 * @param pageName
  	 */
  	protected WizardPageWithNotification(String pageName) {
  		super(pageName);
  	}
  	
      protected WizardPageWithNotification(String pageName, String title,
              ImageDescriptor titleImage) {
      	super(pageName, title, titleImage);
      }
  
  	
      public void pageEntered(int button) {}
      public void pageExited(int button) {}
  }
  
  
  
  1.9       +5 -15     jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/wizards/NewJARWizard.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NewJARWizard.java
  ===================================================================
  RCS file: NewJARWizard.java
  diff -N NewJARWizard.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ NewJARWizard.java	16 Apr 2007 17:56:54 -0000	1.9
  @@ -0,0 +1,42 @@
  +package org.jboss.ide.eclipse.packages.ui.wizards;
  +
  +import org.eclipse.jface.resource.ImageDescriptor;
  +import org.eclipse.jface.wizard.WizardPage;
  +import org.jboss.ide.eclipse.packages.core.Trace;
  +import org.jboss.ide.eclipse.packages.core.model.IPackage;
  +import org.jboss.ide.eclipse.packages.core.model.PackagesCore;
  +import org.jboss.ide.eclipse.packages.core.model.types.JARPackageType;
  +import org.jboss.ide.eclipse.packages.ui.PackagesSharedImages;
  +import org.jboss.ide.eclipse.packages.ui.PackagesUIMessages;
  +
  +public class NewJARWizard extends AbstractPackageWizard
  +{
  +	public WizardPage[] createWizardPages() {
  +		return new WizardPage[0];
  +	}
  +
  +	public NewJARWizard () {
  +		setWindowTitle(PackagesUIMessages.NewJARWizard_windowTitle);
  +	}
  +	
  +	public NewJARWizard (IPackage existingPackage) {
  +		super(existingPackage);
  +		
  +		setWindowTitle(PackagesUIMessages.NewJARWizard_windowTitle_editJAR);
  +	}
  +	
  +	public boolean performFinish(IPackage pkg) {
  +		Trace.trace(getClass(), "performing finish");
  +		
  +		pkg.setPackageType(PackagesCore.getPackageType(JARPackageType.TYPE_ID));
  +		return true;
  +	}
  +	
  +	public ImageDescriptor getImageDescriptor() {
  +		return PackagesSharedImages.getImageDescriptor(PackagesSharedImages.IMG_NEW_JAR_WIZARD);
  +	}
  +	
  +	public String getPackageExtension() {
  +		return "jar";
  +	}
  +}
  
  
  
  1.1      date: 2007/04/16 17:56:54;  author: rawb;  state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/wizards/WizardWithNotification.java
  
  Index: WizardWithNotification.java
  ===================================================================
  /**
   * JBoss, a Division of Red Hat
   * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
  * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software 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.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.ide.eclipse.packages.ui.wizards;
  
  import org.eclipse.jface.dialogs.IPageChangedListener;
  import org.eclipse.jface.dialogs.PageChangedEvent;
  import org.eclipse.jface.wizard.IWizardContainer;
  import org.eclipse.jface.wizard.IWizardPage;
  import org.eclipse.jface.wizard.Wizard;
  import org.eclipse.jface.wizard.WizardDialog;
  
  /**
   *
   * @author rob.stryker at jboss.com
   */
  public abstract class WizardWithNotification extends Wizard implements IPageChangedListener {
  	public static final int NEXT = 1;
  	public static final int PREVIOUS = 2;
  	public static final int FINISH = 3;
  	public static final int UNKNOWN = 4;
  	
  	
  	private IWizardPage currentPage;
  	public WizardWithNotification() {
  		super();
  		currentPage = null;
  	}
      public void setContainer(IWizardContainer wizardContainer) {
      	IWizardContainer previous = getContainer();
      	super.setContainer(wizardContainer);
      	
      	// listeners
      	if( previous instanceof WizardDialog ) {
      		((WizardDialog)previous).removePageChangedListener(this);
      	}
      	
      	if( wizardContainer instanceof WizardDialog ) {
      		((WizardDialog)wizardContainer).addPageChangedListener(this);
      	}
      }
  	public void pageChanged(PageChangedEvent event) {
  		if( currentPage == null ) {
  			currentPage = (IWizardPage)event.getSelectedPage();
  			if( currentPage instanceof WizardPageWithNotification) {
  				((WizardPageWithNotification)currentPage).pageEntered(UNKNOWN);
  			}
  			return;
  		}
  		
  		Object selectedPage = event.getSelectedPage();
  		IWizardPage previous = currentPage.getPreviousPage();
  		IWizardPage next = currentPage.getNextPage();
  		
  		if( previous != null && previous.equals(selectedPage)) {
  			if( currentPage instanceof WizardPageWithNotification ) 
  				((WizardPageWithNotification)currentPage).pageExited(PREVIOUS);
  			if( selectedPage instanceof WizardPageWithNotification ) 
  				((WizardPageWithNotification)selectedPage).pageEntered(PREVIOUS);
  		} else if( next != null && next.equals(selectedPage)) {
  			if( currentPage instanceof WizardPageWithNotification ) 
  				((WizardPageWithNotification)currentPage).pageExited(NEXT);
  			if( selectedPage instanceof WizardPageWithNotification ) 
  				((WizardPageWithNotification)selectedPage).pageEntered(NEXT);
  		} else {
  			if( currentPage instanceof WizardPageWithNotification ) {
  				((WizardPageWithNotification)currentPage).pageExited(UNKNOWN);
  			}
  			if( selectedPage instanceof WizardPageWithNotification) {
  				((WizardPageWithNotification)selectedPage).pageEntered(UNKNOWN);
  			}
  		}
  		currentPage = selectedPage instanceof IWizardPage ? ((IWizardPage)selectedPage) : null;
  	}
  
  
  }
  
  
  
  1.12      +10 -33    jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/wizards/FilesetWizard.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FilesetWizard.java
  ===================================================================
  RCS file: FilesetWizard.java
  diff -N FilesetWizard.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ FilesetWizard.java	16 Apr 2007 17:56:54 -0000	1.12
  @@ -0,0 +1,69 @@
  +package org.jboss.ide.eclipse.packages.ui.wizards;
  +
  +import java.lang.reflect.InvocationTargetException;
  +
  +import org.eclipse.core.resources.ResourcesPlugin;
  +import org.eclipse.core.runtime.IPath;
  +import org.eclipse.core.runtime.IProgressMonitor;
  +import org.eclipse.core.runtime.Path;
  +import org.eclipse.jface.operation.IRunnableWithProgress;
  +import org.eclipse.jface.wizard.Wizard;
  +import org.jboss.ide.eclipse.packages.core.Trace;
  +import org.jboss.ide.eclipse.packages.core.model.IPackageFileSet;
  +import org.jboss.ide.eclipse.packages.core.model.IPackageNode;
  +import org.jboss.ide.eclipse.packages.core.model.internal.PackagesModel;
  +import org.jboss.ide.eclipse.packages.ui.PackageNodeFactory;
  +import org.jboss.ide.eclipse.packages.ui.wizards.pages.FilesetInfoWizardPage;
  +
  +public class FilesetWizard extends Wizard {
  +
  +	private FilesetInfoWizardPage page1;
  +	private IPackageFileSet fileset;
  +	private IPackageNode parentNode;
  +	
  +	public FilesetWizard(IPackageFileSet fileset, IPackageNode parentNode)
  +	{
  +		this.fileset = fileset;
  +		this.parentNode = parentNode;
  +	}
  +	
  +	public boolean performFinish() {
  +		try {
  +		final boolean createFileset = this.fileset == null;
  +		
  +		if (createFileset)
  +			this.fileset = PackageNodeFactory.createFileset();
  +				
  +		fillFilesetFromPage(fileset);
  +		try {
  +			getContainer().run(false, false, new IRunnableWithProgress () {
  +				public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
  +					if (createFileset) {
  +						PackagesModel.instance().attach(parentNode, fileset, monitor);
  +					} else {
  +						PackagesModel.instance().saveModel(fileset.getProject(), monitor);
  +					}
  +				}
  +			});
  +		} catch (InvocationTargetException e) {
  +			Trace.trace(getClass(), e);
  +		} catch (InterruptedException e) {
  +			Trace.trace(getClass(), e);
  +		}
  +		
  +		} catch(Exception e) {e.printStackTrace();}
  +		return true;
  +	}
  +	
  +	private void fillFilesetFromPage (IPackageFileSet fileset) {
  +		fileset.setExcludesPattern(page1.getExcludes());
  +		fileset.setIncludesPattern(page1.getIncludes());
  +		fileset.setInWorkspace(page1.isRootDirWorkspaceRelative());
  +		fileset.setSourcePath(new Path(page1.getRootDir()));
  +	}
  +
  +	public void addPages() {
  +		page1 = new FilesetInfoWizardPage(getShell(), fileset, parentNode);
  +		addPage(page1);
  +	}
  +}
  
  
  



More information about the jboss-cvs-commits mailing list