[jboss-cvs] jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/util ...
Robert Stryker
rob.stryker at jboss.com
Wed Apr 18 12:52:15 EDT 2007
User: rawb
Date: 07/04/18 12:52:15
Added: core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/util
PackageDestinationComposite.java
DestinationChangeListener.java
PackageNodeDestinationComposite.java
FilesetPreviewComposite.java
Log:
refactored to archive rather than package, a la max
Revision Changes Path
1.1 date: 2007/04/18 16:52:15; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/PackageDestinationComposite.java
Index: PackageDestinationComposite.java
===================================================================
package org.jboss.ide.eclipse.archives.ui.util;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.ui.PackagesSharedImages;
import org.jboss.ide.eclipse.archives.ui.PackagesUIMessages;
public class PackageDestinationComposite extends PackageNodeDestinationComposite {
protected boolean inWorkspace;
protected Button filesystemBrowseButton, workspaceBrowseButton;
public PackageDestinationComposite (Composite parent, int style, Object destination) {
super(parent, style, destination);
}
// public PackageDestinationComposite (Composite parent, int style, GridData textLayoutData, GridData buttonLayoutData, Object destination)
// {
// super (parent, style, textLayoutData, buttonLayoutData, destination);
// }
//
protected void fillBrowseComposite(Composite parent) {
Composite browseComposite = new Composite(parent, SWT.NONE);
browseComposite.setLayout(new GridLayout(2, false));
workspaceBrowseButton = new Button(browseComposite, SWT.PUSH);
workspaceBrowseButton.setText(PackagesUIMessages.PackageDestinationComposite_workspaceBrowseButton_label);
workspaceBrowseButton.addSelectionListener(new SelectionAdapter () {
public void widgetSelected(SelectionEvent e) {
openDestinationDialog();
}
});
filesystemBrowseButton = new Button(browseComposite, SWT.PUSH);
filesystemBrowseButton.setText(PackagesUIMessages.PackageDestinationComposite_filesystemBrowseButton_label);
filesystemBrowseButton.addSelectionListener(new SelectionAdapter () {
public void widgetSelected(SelectionEvent e) {
browseFilesystem();
}
});
}
protected void browseFilesystem ()
{
DirectoryDialog dialog = new DirectoryDialog(getShell());
String currentPath = destinationText.getText();
if (currentPath != null && currentPath.length() > 0 && !inWorkspace)
{
dialog.setFilterPath(destinationText.getText());
}
String path = dialog.open();
if (path != null)
{
nodeDestination = new Path(path);
updateDestinationViewer();
}
}
protected void updateDestinationViewer()
{
super.updateDestinationViewer();
if (nodeDestination instanceof IPath)
{
inWorkspace = false;
IPath path = (IPath) nodeDestination;
setDestinationText(path.toString());
setDestinationImage(PackagesSharedImages.getImage(PackagesSharedImages.IMG_EXTERNAL_FILE));
}
else if (nodeDestination instanceof IContainer || nodeDestination instanceof IArchiveNode)
{
inWorkspace = true;
}
}
public void setEditable(boolean editable) {
super.setEditable(editable);
workspaceBrowseButton.setEnabled(editable);
filesystemBrowseButton.setEnabled(editable);
}
}
1.1 date: 2007/04/18 16:52:15; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/DestinationChangeListener.java
Index: DestinationChangeListener.java
===================================================================
package org.jboss.ide.eclipse.archives.ui.util;
public interface DestinationChangeListener {
public void destinationChanged (Object newDestination);
}
1.1 date: 2007/04/18 16:52:15; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/PackageNodeDestinationComposite.java
Index: PackageNodeDestinationComposite.java
===================================================================
package org.jboss.ide.eclipse.archives.ui.util;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.ui.PackagesSharedImages;
import org.jboss.ide.eclipse.archives.ui.PackagesUIMessages;
import org.jboss.ide.eclipse.archives.ui.dialogs.PackageNodeDestinationDialog;
public class PackageNodeDestinationComposite extends Composite {
protected Composite parent;
protected Label destinationImage;
protected Text destinationText;
protected Button destinationBrowseButton;
protected Object nodeDestination;
protected boolean editable;
protected ArrayList listeners;
public PackageNodeDestinationComposite(Composite parent, int style, Object destination) {
super(parent, style);
this.parent = parent;
this.nodeDestination = destination;
this.editable = true;
this.listeners = new ArrayList();
createComposite();
}
protected void createComposite() {
setLayout(new FormLayout());
// create widgets
destinationImage = new Label(this, SWT.NONE);
destinationText = new Text(this, SWT.BORDER);
Composite browseComposite = new Composite(this, SWT.NONE);
// set up their layout positioning
destinationImage.setLayoutData(createFormData(0,5,null, 0, 0, 5, null, 0));
destinationText.setLayoutData(createFormData(0, 5, null, 0, destinationImage, 5, browseComposite, -5));
// set text, add listeners, etc
destinationText.setEditable(false);
browseComposite.setLayout(new FillLayout());
browseComposite.setLayoutData(createFormData(0,0,null,0,null,0,100,-5));
fillBrowseComposite(browseComposite);
// call other functions required for startup
updateDestinationViewer();
}
protected void fillBrowseComposite(Composite browseComposite) {
destinationBrowseButton = new Button(browseComposite, SWT.PUSH);
destinationBrowseButton.setText(PackagesUIMessages.PackageNodeDestinationComposite_destinationBrowseButton_label);
destinationBrowseButton.addSelectionListener(new SelectionAdapter () {
public void widgetSelected(SelectionEvent e) {
openDestinationDialog();
}
});
destinationBrowseButton.setEnabled(editable);
}
private FormData createFormData(Object topStart, int topOffset, Object bottomStart, int bottomOffset,
Object leftStart, int leftOffset, Object rightStart, int rightOffset) {
FormData data = new FormData();
if( topStart != null ) {
data.top = topStart instanceof Control ? new FormAttachment((Control)topStart, topOffset) :
new FormAttachment(((Integer)topStart).intValue(), topOffset);
}
if( bottomStart != null ) {
data.bottom = bottomStart instanceof Control ? new FormAttachment((Control)bottomStart, bottomOffset) :
new FormAttachment(((Integer)bottomStart).intValue(), bottomOffset);
}
if( leftStart != null ) {
data.left = leftStart instanceof Control ? new FormAttachment((Control)leftStart, leftOffset) :
new FormAttachment(((Integer)leftStart).intValue(), leftOffset);
}
if( rightStart != null ) {
data.right = rightStart instanceof Control ? new FormAttachment((Control)rightStart, rightOffset) :
new FormAttachment(((Integer)rightStart).intValue(), rightOffset);
}
return data;
}
protected void openDestinationDialog ()
{
PackageNodeDestinationDialog dialog = new PackageNodeDestinationDialog(getShell(), nodeDestination, true, true);
if (nodeDestination != null)
dialog.setInitialSelection(nodeDestination);
int response = dialog.open();
if (response == Dialog.OK)
{
Object object = dialog.getResult()[0];
nodeDestination = object;
updateDestinationViewer();
fireDestinationChanged();
}
}
public void setPackageNodeDestination (Object destination)
{
nodeDestination = destination;
updateDestinationViewer();
}
protected void setDestinationImage (Image image)
{
destinationImage.setImage(image);
}
protected void setDestinationText (String text)
{
destinationText.setText(text);
}
protected void updateDestinationViewer ()
{
if (nodeDestination == null) return;
destinationText.setText("");
if (nodeDestination instanceof IArchive)
{
IArchive pkg = (IArchive) nodeDestination;
if (pkg.isTopLevel())
{
setDestinationText(pkg.getName());
} else {
setDestinationText(pkg.getRootArchiveRelativePath().toOSString());
}
if (pkg.isExploded()) {
setDestinationImage(PackagesSharedImages.getImage(PackagesSharedImages.IMG_PACKAGE_EXPLODED));
} else {
setDestinationImage(PackagesSharedImages.getImage(PackagesSharedImages.IMG_PACKAGE));
}
}
else if (nodeDestination instanceof IArchiveFolder)
{
IArchiveFolder folder = (IArchiveFolder) nodeDestination;
setDestinationText(folder.getRootArchiveRelativePath().toString());
setDestinationImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
}
else if (nodeDestination instanceof IProject)
{
IProject project = (IProject) nodeDestination;
setDestinationText(project.getName());
setDestinationImage(PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT));
}
else if (nodeDestination instanceof IFolder)
{
IFolder folder = (IFolder) nodeDestination;
setDestinationText("/" + folder.getProject().getName() + "/" + folder.getProjectRelativePath().toString());
setDestinationImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
}
}
public Object getPackageNodeDestination ()
{
return nodeDestination;
}
public void setEditable(boolean editable) {
this.editable = editable;
if (destinationBrowseButton != null)
{
destinationBrowseButton.setEnabled(editable);
}
}
public void addDestinationChangeListener (DestinationChangeListener listener)
{
listeners.add(listener);
}
public void removeDestinationChangeListener (DestinationChangeListener listener)
{
listeners.remove(listener);
}
private void fireDestinationChanged ()
{
for (Iterator iter = listeners.iterator(); iter.hasNext(); )
{
DestinationChangeListener listener = (DestinationChangeListener) iter.next();
listener.destinationChanged(nodeDestination);
}
}
}
1.1 date: 2007/04/18 16:52:15; author: rawb; state: Exp;jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/archives/ui/util/FilesetPreviewComposite.java
Index: FilesetPreviewComposite.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.util;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
/**
*
* @author rob.stryker at jboss.com
*/
public class FilesetPreviewComposite extends Composite {
private IPath folder;
private TableViewer previewTable;
public FilesetPreviewComposite (Composite parent, int style) {
super(parent, style);
previewTable = new TableViewer(this, SWT.BORDER);
previewTable.setContentProvider(new ArrayContentProvider());
previewTable.setLabelProvider(new ResourceLabelProvider());
setLayout(new FormLayout());
FormData data = new FormData();
data.left = new FormAttachment(0,5);
data.right = new FormAttachment(100,-5);
data.top = new FormAttachment(0,5);
data.bottom = new FormAttachment(100,-5);
previewTable.getTable().setLayoutData(data);
}
public FilesetPreviewComposite (Composite parent)
{
this(parent, SWT.NONE);
}
public void setInput(Object[] o) {
previewTable.setInput(o);
}
public void setEnabled(boolean bool) {
previewTable.getTable().setEnabled(bool);
}
public void clearAll() {
previewTable.getTable().clearAll();
}
public void setRootFolder(IPath folder) {
this.folder = folder;
}
// private IPath getContainerRelativePath(IContainer container, IResource resource)
// {
// String path = "";
// IContainer parent = resource.getParent();
// while (parent != null)
// {
// if (parent.equals(container))
// {
// break;
// }
// path = parent.getName() + "/" + path;
// parent = parent.getParent();
// }
//
// path += (path.length() == 0 ? "" : "/") + resource.getName();
//
// return new Path(path);
// }
private String getFolderRelativePath(IPath root, IPath resource) {
IPath out = resource.removeFirstSegments(resource.matchingFirstSegments(root));
String out2 = "";
for( int i = 0; i < out.segmentCount(); i++ ) {
out2 += Path.SEPARATOR + out.segment(i);
}
return out2;
}
private class ResourceLabelProvider implements ILabelProvider
{
public Image getImage(Object element) {
if (element instanceof IResource)
{
IResource resource = (IResource) element;
if (resource.getType() == IResource.PROJECT)
{
return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
}
else if (resource.getType() == IResource.FOLDER)
{
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
else if (resource.getType() == IResource.FILE)
{
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
}
} else if (element instanceof IPath) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
}
return null;
}
public String getText(Object element) {
return element.toString();
}
public void addListener(ILabelProviderListener listener) {}
public void dispose() {}
public boolean isLabelProperty(Object element, String property) {
return true;
}
public void removeListener(ILabelProviderListener listener) { }
}
}
More information about the jboss-cvs-commits
mailing list