Index: PackageExplorerActionGroup.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerActionGroup.java,v
retrieving revision 1.70
diff -u -r1.70 PackageExplorerActionGroup.java
--- PackageExplorerActionGroup.java 6 Jun 2005 07:43:34 -0000 1.70
+++ PackageExplorerActionGroup.java 15 Jul 2005 07:03:32 -0000
@@ -244,7 +244,8 @@
int type= ((IJavaElement)element).getElementType();
return type == IJavaElement.JAVA_PROJECT ||
type == IJavaElement.PACKAGE_FRAGMENT_ROOT ||
- type == IJavaElement.PACKAGE_FRAGMENT;
+ type == IJavaElement.PACKAGE_FRAGMENT ||
+ type == IJavaElement.COMPILATION_UNIT;
}
if (element instanceof IWorkingSet) {
return true;
Index: PackageExplorerPart.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerPart.java,v
retrieving revision 1.250
diff -u -r1.250 PackageExplorerPart.java
--- PackageExplorerPart.java 16 Jun 2005 10:56:54 -0000 1.250
+++ PackageExplorerPart.java 15 Jul 2005 07:03:33 -0000
@@ -1954,6 +1954,10 @@
}
}
+ public PackageExplorerActionGroup getActionSet() {
+ return fActionSet;
+ }
+
//---- test methods for working set mode -------------------------------
public void internalTestShowWorkingSets(IWorkingSet[] workingSets) {
Index: AddSplitPartAction.java
===================================================================
RCS file: AddSplitPartAction.java
diff -N AddSplitPartAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AddSplitPartAction.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,32 @@
+
+package org.eclipse.jdt.internal.ui.packageview;
+
+import org.eclipse.jface.action.Action;
+
+// import org.eclipse.ui.PlatformUI;
+// import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+
+
+class AddSplitPartAction extends Action {
+ private SplitPackageExplorerPart splitPart;
+
+ AddSplitPartAction( SplitPackageExplorerPart splitPart) {
+ super( "Add Split");
+ setDescription( "Add split part");
+ setToolTipText( "Add split");
+ JavaPluginImages.setLocalImageDescriptors( this, "bar_plus.gif"); //$NON-NLS-1$
+// super( PackagesMessages.CollapseAllAction_label);
+// setDescription( PackagesMessages.CollapseAllAction_description);
+// setToolTipText( PackagesMessages.CollapseAllAction_tooltip);
+// JavaPluginImages.setLocalImageDescriptors( this, "collapseall.gif"); //$NON-NLS-1$
+
+ this.splitPart = splitPart;
+ // PlatformUI.getWorkbench().getHelpSystem().setHelp( this, IJavaHelpContextIds.COLLAPSE_ALL_ACTION);
+ }
+
+ public void run() {
+ splitPart.addSplit();
+ }
+
+}
Index: RemoveSplitPartAction.java
===================================================================
RCS file: RemoveSplitPartAction.java
diff -N RemoveSplitPartAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RemoveSplitPartAction.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,32 @@
+
+package org.eclipse.jdt.internal.ui.packageview;
+
+import org.eclipse.jface.action.Action;
+
+// import org.eclipse.ui.PlatformUI;
+// import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+
+
+class RemoveSplitPartAction extends Action {
+ private SplitPackageExplorerPart splitPart;
+
+ RemoveSplitPartAction( SplitPackageExplorerPart splitPart) {
+ super( "Remove Split");
+ setDescription( "Remove Split part");
+ setToolTipText( "Remove Split");
+ JavaPluginImages.setLocalImageDescriptors( this, "bar_minus.gif"); //$NON-NLS-1$
+// super( PackagesMessages.CollapseAllAction_label);
+// setDescription( PackagesMessages.CollapseAllAction_description);
+// setToolTipText( PackagesMessages.CollapseAllAction_tooltip);
+// JavaPluginImages.setLocalImageDescriptors( this, "collapseall.gif"); //$NON-NLS-1$
+
+ this.splitPart = splitPart;
+ // PlatformUI.getWorkbench().getHelpSystem().setHelp( this, IJavaHelpContextIds.COLLAPSE_ALL_ACTION);
+ }
+
+ public void run() {
+ this.splitPart.removeSplit();
+ }
+
+}
Index: SplitPackageExplorerPart.java
===================================================================
RCS file: SplitPackageExplorerPart.java
diff -N SplitPackageExplorerPart.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SplitPackageExplorerPart.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,337 @@
+
+package org.eclipse.jdt.internal.ui.packageview;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+//import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeViewer;
+
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.ISetSelectionTarget;
+import org.eclipse.ui.part.IShowInTarget;
+import org.eclipse.ui.part.ShowInContext;
+import org.eclipse.ui.part.ViewPart;
+
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider;
+import org.eclipse.jdt.ui.IPackagesViewPart;
+
+
+public class SplitPackageExplorerPart extends ViewPart
+ implements ISetSelectionTarget, IShowInTarget,
+ IPackagesViewPart, IPropertyChangeListener, IViewPartInputProvider {
+ // orientations
+ static final int VIEW_ORIENTATION_VERTICAL = 0;
+ static final int VIEW_ORIENTATION_HORIZONTAL = 1;
+ static final int VIEW_ORIENTATION_AUTOMATIC = 2;
+
+ /**
+ * The current orientation; either VIEW_ORIENTATION_HORIZONTAL
+ * VIEW_ORIENTATION_VERTICAL
, or VIEW_ORIENTATION_AUTOMATIC
.
+ */
+ int orientation = VIEW_ORIENTATION_AUTOMATIC;
+ /**
+ * The current orientation; either VIEW_ORIENTATION_HORIZONTAL
+ * VIEW_ORIENTATION_VERTICAL
.
+ */
+ private int currentOrientation = VIEW_ORIENTATION_AUTOMATIC;
+
+
+ private IMemento memento;
+
+ private List splits = new ArrayList();
+ private PackageExplorerPart currentPart;
+
+ private SashForm form;
+ private ControlAdapter formControlListener;
+
+ private IAction addSplitPartAction;
+ private IAction removeSplitPartAction;
+ private ToggleOrientationAction[] toggleOrientationActions;
+
+
+ public SplitPackageExplorerPart() {
+ }
+
+ // ViewPart
+ public void init( IViewSite site, IMemento memento) throws PartInitException {
+ super.init(site);
+ this.memento = memento;
+ }
+
+ // ViewPart
+ public void createPartControl( Composite parent) {
+ addSplitPartAction = new AddSplitPartAction(this);
+ removeSplitPartAction = new RemoveSplitPartAction(this);
+
+ formControlListener = new ControlAdapter() {
+ public void controlResized(ControlEvent e) {
+ computeOrientation();
+ }
+ };
+ form = new SashForm( parent, SWT.VERTICAL);
+ form.setLayout( new FillLayout());
+ form.addControlListener(formControlListener);
+
+ toggleOrientationActions = new ToggleOrientationAction[] {
+ new ToggleOrientationAction(VIEW_ORIENTATION_VERTICAL),
+ new ToggleOrientationAction(VIEW_ORIENTATION_HORIZONTAL),
+ new ToggleOrientationAction(VIEW_ORIENTATION_AUTOMATIC)};
+ setOrientation(VIEW_ORIENTATION_AUTOMATIC);
+
+// getViewSite().getActionBars().getMenuManager().addMenuListener( new IMenuListener() {
+// public void menuAboutToShow( IMenuManager manager) {
+// // System.err.println( "### SplitPackageExplorerPart.menuAboutToShow()");
+// }
+// });
+
+ createPackageExplorerPart();
+
+ addSplitActions();
+ }
+
+ void computeOrientation() {
+ if (currentOrientation == VIEW_ORIENTATION_AUTOMATIC) {
+ Point size = form.getSize();
+ if (size.x != 0 && size.y != 0) {
+ setOrientation( size.x > size.y ? VIEW_ORIENTATION_HORIZONTAL : VIEW_ORIENTATION_VERTICAL);
+ }
+ } else {
+ setOrientation( currentOrientation);
+ }
+ }
+
+ private void setOrientation(int orientation) {
+ form.setOrientation((orientation == VIEW_ORIENTATION_HORIZONTAL) ? SWT.HORIZONTAL : SWT.VERTICAL);
+
+ for (int i = 0; i < toggleOrientationActions.length; ++i) {
+ toggleOrientationActions[i].setChecked(orientation == toggleOrientationActions[i].getOrientation());
+ }
+
+ // GridLayout layout= (GridLayout) fCounterComposite.getLayout();
+ // setCounterColumns(layout);
+ form.layout();
+ }
+
+
+ private void createPackageExplorerPart() {
+ PackageExplorerPart part = new PackageExplorerPart();
+ try {
+ part.init( getViewSite(), this.memento);
+ } catch( PartInitException ex) {
+ throw new RuntimeException( ex.toString());
+ }
+ part.createPartControl(form);
+
+ splits.add(part);
+
+ setCurrentPart(part);
+
+ part.getTreeViewer().getTree().addFocusListener( new SplitFocusListener( this, part));
+ }
+
+ // ViewPart
+ public void setFocus() {
+ if(currentPart!=null) {
+ currentPart.setFocus();
+ }
+ }
+
+
+ // ISetSelectionTarget
+ public void selectReveal( ISelection selection) {
+ currentPart.selectReveal(selection);
+ }
+
+ // IMenuListener
+// public void menuAboutToShow( IMenuManager manager) {
+// System.err.println( "### SplitPackageExplorerPart.menuAboutToShow()");
+// // TODO any cleanup?
+// currentPart.menuAboutToShow(manager);
+// }
+
+ // IShowInTarget
+ public boolean show( ShowInContext context) {
+ return currentPart.show(context);
+ }
+
+ // IPackagesViewPart (require smart selection!)
+ public void selectAndReveal( Object element) {
+ currentPart.selectAndReveal(element);
+ }
+
+ // IPackagesViewPart (current viewer)
+ public TreeViewer getTreeViewer() {
+ return currentPart.getTreeViewer();
+ }
+
+ // IPropertyChangeListener
+ public void propertyChange( PropertyChangeEvent event) {
+ currentPart.propertyChange(event);
+ }
+
+ // IViewPartInputProvider
+ public Object getViewPartInput() {
+ return currentPart.getViewPartInput();
+ }
+
+
+ public void saveState( IMemento memento) {
+ ((PackageExplorerPart) this.splits.get( 0)).saveState(memento);
+ }
+
+ public Object getAdapter( Class key) {
+ return currentPart.getAdapter( key);
+ }
+
+ public void dispose() {
+ for( Iterator it = splits.iterator(); it.hasNext();) {
+ PackageExplorerPart part = ( PackageExplorerPart) it.next();
+ part.dispose();
+ }
+
+ form.removeControlListener(formControlListener);
+ form.dispose();
+
+ super.dispose();
+ }
+
+ public String getTitleToolTip() {
+ return currentPart.getTitleToolTip();
+ }
+
+
+ // Splits
+
+ public void setCurrentPart( PackageExplorerPart currentPart) {
+ this.currentPart = currentPart;
+ }
+
+ public void addSplitActions() {
+ IMenuManager menu = getViewSite().getActionBars().getMenuManager();
+ menu.add(new Separator());
+ menu.add(addSplitPartAction);
+ menu.add(removeSplitPartAction);
+
+ menu.add(new Separator());
+ for (int i = 0; i < toggleOrientationActions.length; ++i) {
+ menu.add(toggleOrientationActions[i]);
+ }
+ }
+
+ public void activatePart(PackageExplorerPart currentPart) {
+ if(this.currentPart==currentPart) {
+ return;
+ }
+
+ IActionBars actionBars = getViewSite().getActionBars();
+ actionBars.getToolBarManager().removeAll();
+ actionBars.getMenuManager().removeAll();
+ currentPart.getActionSet().fillActionBars(actionBars);
+
+ setCurrentPart(currentPart);
+
+ addSplitActions();
+ currentPart.setFocus();
+
+ getSite().setSelectionProvider(currentPart.getTreeViewer());
+ }
+
+ public void addSplit() {
+ if(currentPart!=null) {
+ IActionBars actionBars = currentPart.getViewSite().getActionBars();
+ actionBars.getToolBarManager().removeAll();
+ actionBars.getMenuManager().removeAll();
+ }
+
+ createPackageExplorerPart();
+ form.layout();
+ }
+
+ public void removeSplit() {
+ splits.remove(currentPart);
+
+ currentPart.getTreeViewer().getTree().dispose();
+ currentPart.dispose();
+ currentPart = null;
+
+ form.layout();
+
+ PackageExplorerPart part = ( PackageExplorerPart) splits.get( 0);
+ activatePart(part);
+ }
+
+
+ private static final class SplitFocusListener extends FocusAdapter {
+ private final SplitPackageExplorerPart splitPart;
+ private final PackageExplorerPart currentPart;
+
+ public SplitFocusListener( SplitPackageExplorerPart splitPart, PackageExplorerPart currentPart) {
+ this.splitPart = splitPart;
+ this.currentPart = currentPart;
+ }
+
+ public void focusGained( FocusEvent e) {
+ splitPart.activatePart(currentPart);
+ }
+
+ }
+
+
+ private class ToggleOrientationAction extends Action {
+ private final int actionOrientation;
+
+ public ToggleOrientationAction(int orientation) {
+ super("", AS_RADIO_BUTTON); //$NON-NLS-1$
+
+ if (orientation == VIEW_ORIENTATION_HORIZONTAL) {
+ setText( "Horizontal View Orientation"); //$NON-NLS-1$
+ JavaPluginImages.setLocalImageDescriptors( this, "th_horizontal.gif"); //$NON-NLS-1$
+ } else if (orientation == VIEW_ORIENTATION_VERTICAL) {
+ setText( "Vertical View Orientation"); //$NON-NLS-1$
+ JavaPluginImages.setLocalImageDescriptors( this, "th_vertical.gif"); //$NON-NLS-1$
+ } else if (orientation == VIEW_ORIENTATION_AUTOMATIC) {
+ setText( "Automatic View Orientation"); //$NON-NLS-1$
+ JavaPluginImages.setLocalImageDescriptors( this, "th_automatic.gif"); //$NON-NLS-1$
+ }
+ actionOrientation = orientation;
+ // WorkbenchHelp.setHelp(this, IJUnitHelpContextIds.RESULTS_VIEW_TOGGLE_ORIENTATION_ACTION);
+ }
+
+ public int getOrientation() {
+ return actionOrientation;
+ }
+
+ public void run() {
+ if (isChecked()) {
+ currentOrientation = actionOrientation;
+ computeOrientation();
+ }
+ }
+ }
+
+
+
+}