[jboss-cvs] jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards ...
Robert Stryker
rob.stryker at jboss.com
Wed Apr 18 12:52:16 EDT 2007
User: rawb
Date: 07/04/18 12:52:16
Added: core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards
FilesetWizard.java AbstractPackageWizard.java
WizardWithNotification.java NewJARWizard.java
WizardPageWithNotification.java
Log:
refactored to archive rather than package, a la max
Revision Changes Path
1.1 date: 2007/04/18 16:52:16; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/FilesetWizard.java
Index: FilesetWizard.java
===================================================================
package org.jboss.ide.eclipse.archives.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.archives.core.Trace;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.internal.ArchivesModel;
import org.jboss.ide.eclipse.archives.ui.PackageNodeFactory;
import org.jboss.ide.eclipse.archives.ui.wizards.pages.FilesetInfoWizardPage;
public class FilesetWizard extends Wizard {
private FilesetInfoWizardPage page1;
private IArchiveFileSet fileset;
private IArchiveNode parentNode;
public FilesetWizard(IArchiveFileSet fileset, IArchiveNode 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) {
ArchivesModel.instance().attach(parentNode, fileset, monitor);
} else {
ArchivesModel.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 (IArchiveFileSet 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);
}
}
1.1 date: 2007/04/18 16:52:16; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/AbstractPackageWizard.java
Index: AbstractPackageWizard.java
===================================================================
package org.jboss.ide.eclipse.archives.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.archives.core.Trace;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.internal.ArchivesModel;
import org.jboss.ide.eclipse.archives.ui.views.ProjectArchivesView;
import org.jboss.ide.eclipse.archives.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 IArchive existingPackage;
public AbstractPackageWizard () {
this.project = ProjectArchivesView.getInstance().getCurrentProject();
}
public AbstractPackageWizard (IArchive 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 IArchive 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 {
IArchiveNode parent = null;
if (destination instanceof IArchiveNode) {
// 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 = (IArchiveNode)destination;
} else {
parent = ArchivesModel.instance().getRoot(project, true, monitor);
}
if( create )
ArchivesModel.instance().attach(parent, pkg, monitor);
else
ArchivesModel.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 = ProjectArchivesView.getInstance().getCurrentProject();
Object selected;
if( selection.isEmpty() ) {
selected = project;
} else {
selected = selection.getFirstElement();
}
if (selected instanceof IArchiveNode)
{
IArchiveNode node = (IArchiveNode) selected;
if (node.getNodeType() == IArchiveNode.TYPE_ARCHIVE || node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_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(IArchive 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 IArchive getPackage () {
return firstPage.getPackage();
}
}
1.1 date: 2007/04/18 16:52:16; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/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.archives.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.1 date: 2007/04/18 16:52:16; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/wizards/NewJARWizard.java
Index: NewJARWizard.java
===================================================================
package org.jboss.ide.eclipse.archives.ui.wizards;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;
import org.jboss.ide.eclipse.archives.core.Trace;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.PackagesCore;
import org.jboss.ide.eclipse.archives.core.model.types.JARPackageType;
import org.jboss.ide.eclipse.archives.ui.PackagesSharedImages;
import org.jboss.ide.eclipse.archives.ui.PackagesUIMessages;
public class NewJARWizard extends AbstractPackageWizard
{
public WizardPage[] createWizardPages() {
return new WizardPage[0];
}
public NewJARWizard () {
setWindowTitle(PackagesUIMessages.NewJARWizard_windowTitle);
}
public NewJARWizard (IArchive existingPackage) {
super(existingPackage);
setWindowTitle(PackagesUIMessages.NewJARWizard_windowTitle_editJAR);
}
public boolean performFinish(IArchive pkg) {
Trace.trace(getClass(), "performing finish");
pkg.setArchiveType(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/18 16:52:16; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/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.archives.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) {}
}
More information about the jboss-cvs-commits
mailing list