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

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/util    
                        PackageNodeDestinationComposite.java
                        DestinationChangeListener.java
                        FilesetPreviewComposite.java
                        PackageDestinationComposite.java
  Log:
  Complete rewrite of the the two plugins leading to a cleaner, leaner project. 
  
  Revision  Changes    Path
  1.8       +56 -56    jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/util/PackageNodeDestinationComposite.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PackageNodeDestinationComposite.java
  ===================================================================
  RCS file: PackageNodeDestinationComposite.java
  diff -N PackageNodeDestinationComposite.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ PackageNodeDestinationComposite.java	16 Apr 2007 17:56:54 -0000	1.8
  @@ -0,0 +1,218 @@
  +package org.jboss.ide.eclipse.packages.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.packages.core.model.IPackage;
  +import org.jboss.ide.eclipse.packages.core.model.IPackageFolder;
  +import org.jboss.ide.eclipse.packages.ui.PackagesSharedImages;
  +import org.jboss.ide.eclipse.packages.ui.PackagesUIMessages;
  +import org.jboss.ide.eclipse.packages.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 IPackage)
  +		{
  +			IPackage pkg = (IPackage) 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 IPackageFolder)
  +		{
  +			IPackageFolder folder = (IPackageFolder) 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.4       +0 -0      jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/util/DestinationChangeListener.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DestinationChangeListener.java
  ===================================================================
  RCS file: DestinationChangeListener.java
  diff -N DestinationChangeListener.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ DestinationChangeListener.java	16 Apr 2007 17:56:54 -0000	1.4
  @@ -0,0 +1,7 @@
  +package org.jboss.ide.eclipse.packages.ui.util;
  +
  +public interface DestinationChangeListener {
  +
  +	public void destinationChanged (Object newDestination);
  +	
  +}
  
  
  
  1.4       +31 -37    jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/util/FilesetPreviewComposite.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FilesetPreviewComposite.java
  ===================================================================
  RCS file: FilesetPreviewComposite.java
  diff -N FilesetPreviewComposite.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ FilesetPreviewComposite.java	16 Apr 2007 17:56:54 -0000	1.4
  @@ -0,0 +1,148 @@
  +/**
  + * 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.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) { }
  +		
  +	}
  +}
  
  
  
  1.8       +8 -9      jbosside/core/plugins/org.jboss.ide.eclipse.packages.ui/src/main/org/jboss/ide/eclipse/packages/ui/util/PackageDestinationComposite.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PackageDestinationComposite.java
  ===================================================================
  RCS file: PackageDestinationComposite.java
  diff -N PackageDestinationComposite.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ PackageDestinationComposite.java	16 Apr 2007 17:56:54 -0000	1.8
  @@ -0,0 +1,92 @@
  +package org.jboss.ide.eclipse.packages.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.packages.core.model.IPackageNode;
  +import org.jboss.ide.eclipse.packages.ui.PackagesSharedImages;
  +import org.jboss.ide.eclipse.packages.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 IPackageNode)
  +		{
  +			inWorkspace = true;
  +		}
  +	}
  +	
  +	public void setEditable(boolean editable) {
  +		super.setEditable(editable);
  +		
  +		workspaceBrowseButton.setEnabled(editable);
  +		filesystemBrowseButton.setEnabled(editable);
  +	}
  +}
  
  
  



More information about the jboss-cvs-commits mailing list