Issue #659 float button for cool detachable functionality
Former-commit-id:2b1ce9e674
[formerly855193aa77
] [formerlycab515cbfd
[formerly 9b1c62c4851f95ad270b58ceacf756a616f7c136]] Former-commit-id:cab515cbfd
Former-commit-id:633fd997e5
This commit is contained in:
parent
dbcb9b7b87
commit
945095e345
9 changed files with 703 additions and 30 deletions
|
@ -84,7 +84,6 @@ import org.eclipse.ui.IWorkbenchPage;
|
|||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
@ -106,7 +105,6 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
|||
import com.raytheon.uf.viz.collaboration.data.AlertWordWrapper;
|
||||
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
|
||||
import com.raytheon.uf.viz.collaboration.data.CollaborationGroupContainer;
|
||||
import com.raytheon.uf.viz.collaboration.data.InvitationGroupContainer;
|
||||
import com.raytheon.uf.viz.collaboration.data.SessionContainer;
|
||||
import com.raytheon.uf.viz.collaboration.data.SessionGroupContainer;
|
||||
import com.raytheon.uf.viz.collaboration.data.SharedDisplaySessionMgr;
|
||||
|
@ -120,6 +118,7 @@ import com.raytheon.uf.viz.collaboration.ui.session.SessionView;
|
|||
import com.raytheon.uf.viz.core.VizApp;
|
||||
import com.raytheon.uf.viz.core.icon.IconUtil;
|
||||
import com.raytheon.viz.ui.VizWorkbenchManager;
|
||||
import com.raytheon.viz.ui.views.CaveFloatingView;
|
||||
|
||||
/**
|
||||
* This class is the main view to display the user's information and allow the
|
||||
|
@ -138,7 +137,8 @@ import com.raytheon.viz.ui.VizWorkbenchManager;
|
|||
* @author rferrel
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CollaborationGroupView extends ViewPart implements IPartListener {
|
||||
public class CollaborationGroupView extends CaveFloatingView implements
|
||||
IPartListener {
|
||||
public static final String ID = "com.raytheon.uf.viz.collaboration.ui.CollaborationGroupView";
|
||||
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
|
@ -146,8 +146,6 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
|
|||
|
||||
private SessionGroupContainer activeSessionGroup;
|
||||
|
||||
private InvitationGroupContainer activeInvitationGroup;
|
||||
|
||||
private TreeViewer usersTreeViewer;
|
||||
|
||||
private CollaborationGroupContainer topLevel;
|
||||
|
@ -196,7 +194,9 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
|
|||
*/
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
super.createPartControl(parent);
|
||||
this.parent = parent;
|
||||
this.parent.setLayout(new GridLayout());
|
||||
// build the necessary actions for the view
|
||||
createActions();
|
||||
|
||||
|
@ -301,7 +301,6 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
|
|||
.getInfo().getVenueSubject(), "");
|
||||
}
|
||||
session.sendInvitation(ids, invite);
|
||||
activeInvitationGroup.addObject(invite);
|
||||
} catch (CollaborationException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Error sending invitiation", e);
|
||||
|
@ -608,12 +607,6 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
|
|||
// populates the sessions that the user currently is involved with
|
||||
populateActiveSessions();
|
||||
|
||||
activeInvitationGroup = new InvitationGroupContainer();
|
||||
topLevel.addObject(activeInvitationGroup);
|
||||
// populates the active invitations in case a user leaves and wants to
|
||||
// rejoin
|
||||
populateActiveInvitations();
|
||||
|
||||
// populates the groups that the user is a part of
|
||||
populateGroups();
|
||||
|
||||
|
@ -647,10 +640,6 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void populateActiveInvitations() {
|
||||
activeInvitationGroup.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear and populate the groups from the roster manager entries.
|
||||
*/
|
||||
|
@ -971,7 +960,6 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
|
|||
result.getSubject(), b);
|
||||
}
|
||||
session.sendInvitation(usersList, invite);
|
||||
activeInvitationGroup.addObject(invite);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
statusHandler.handle(Priority.ERROR,
|
||||
|
|
|
@ -254,7 +254,7 @@ public class CollaborationUtils {
|
|||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
||||
file = PathManagerFactory.getPathManager().getLocalizationFile(context,
|
||||
"collaboration" + File.separator + "alertWords.xml");
|
||||
if (file.exists()) {
|
||||
if (file.exists() || file.getFile().exists()) {
|
||||
AlertWordWrapper words = (AlertWordWrapper) JAXB.unmarshal(
|
||||
file.getFile(), AlertWordWrapper.class);
|
||||
if (words.getAlertWords() == null) {
|
||||
|
|
|
@ -95,7 +95,6 @@ public class CollaborationAlertWordsPreferencePage extends
|
|||
viewer = new TableViewer(getFieldEditorParent());
|
||||
viewer.setContentProvider(new CollaborationPreferenceContentProvider());
|
||||
viewer.setLabelProvider(new CollaborationPreferencesLabelProvider());
|
||||
viewer.setInput(CollaborationUtils.getAlertWords());
|
||||
viewer.getTable().setLayoutData(data);
|
||||
|
||||
final StringFieldEditor stringEditor = new StringFieldEditor(
|
||||
|
@ -118,14 +117,14 @@ public class CollaborationAlertWordsPreferencePage extends
|
|||
layout.marginHeight = 0;
|
||||
layout.marginWidth = 0;
|
||||
fontComp.setLayout(layout);
|
||||
data = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
data = new GridData(SWT.FILL, SWT.NONE, true, false);
|
||||
data.horizontalSpan = 3;
|
||||
|
||||
fontComp.setLayoutData(data);
|
||||
|
||||
Label fontName = new Label(fontComp, SWT.NONE);
|
||||
fontName.setText("Font");
|
||||
data = new GridData(SWT.FILL, SWT.NONE, true, false);
|
||||
data = new GridData(SWT.FILL, SWT.NONE, true, true);
|
||||
fontName.setLayoutData(data);
|
||||
|
||||
final Label fontLabel = new Label(fontComp, SWT.NONE);
|
||||
|
@ -174,9 +173,13 @@ public class CollaborationAlertWordsPreferencePage extends
|
|||
.getStringValue(), colorEditor.getColorSelector()
|
||||
.getColorValue());
|
||||
word.setFont(fontLabel.getText());
|
||||
int index = viewer.getTable().getSelectionIndex();
|
||||
word.setSoundPath(fileEditor.getStringValue());
|
||||
((List<AlertWord>) viewer.getInput()).set(index, word);
|
||||
int index = viewer.getTable().getSelectionIndex();
|
||||
if (index != -1) {
|
||||
((List<AlertWord>) viewer.getInput()).set(index, word);
|
||||
} else {
|
||||
((List<AlertWord>) viewer.getInput()).add(word);
|
||||
}
|
||||
viewer.refresh();
|
||||
}
|
||||
}
|
||||
|
@ -233,6 +236,7 @@ public class CollaborationAlertWordsPreferencePage extends
|
|||
fileEditor.setStringValue(word.getSoundPath());
|
||||
}
|
||||
});
|
||||
viewer.setInput(CollaborationUtils.getAlertWords());
|
||||
}
|
||||
|
||||
public boolean performOk() {
|
||||
|
|
|
@ -50,7 +50,6 @@ import org.eclipse.swt.layout.GridLayout;
|
|||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
|
||||
|
||||
import sun.audio.AudioData;
|
||||
|
@ -69,6 +68,7 @@ import com.raytheon.uf.viz.collaboration.ui.Activator;
|
|||
import com.raytheon.uf.viz.collaboration.ui.CollaborationUtils;
|
||||
import com.raytheon.uf.viz.core.icon.IconUtil;
|
||||
import com.raytheon.uf.viz.notification.notifier.PopupNotifier;
|
||||
import com.raytheon.viz.ui.views.CaveFloatingView;
|
||||
|
||||
/**
|
||||
* This performs most of the work for creating a View for a peer-to-peer or
|
||||
|
@ -88,7 +88,7 @@ import com.raytheon.uf.viz.notification.notifier.PopupNotifier;
|
|||
* @version 1.0
|
||||
*/
|
||||
|
||||
public abstract class AbstractSessionView extends ViewPart {
|
||||
public abstract class AbstractSessionView extends CaveFloatingView {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(AbstractSessionView.class);
|
||||
|
||||
|
@ -275,12 +275,17 @@ public abstract class AbstractSessionView extends ViewPart {
|
|||
createNotifier(userId, time, body);
|
||||
}
|
||||
|
||||
String name = userId.getName();
|
||||
for (UserId id : userIds) {
|
||||
if (id.equals(userId)) {
|
||||
name = id.getAlias();
|
||||
break;
|
||||
String name = null;
|
||||
if (userId != null) {
|
||||
name = userId.getName();
|
||||
for (UserId id : userIds) {
|
||||
if (id.equals(userId)) {
|
||||
name = id.getAlias();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
name = getPartName();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -423,6 +428,8 @@ public abstract class AbstractSessionView extends ViewPart {
|
|||
*/
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
parent.setLayout(new GridLayout());
|
||||
super.createPartControl(parent);
|
||||
setTitleImage(getImage());
|
||||
setPartName(getSessionName());
|
||||
initComponents(parent);
|
||||
|
|
|
@ -71,6 +71,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
|
|||
import com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueParticipantEvent;
|
||||
import com.raytheon.uf.viz.collaboration.comm.identity.event.ParticipantEventType;
|
||||
import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo;
|
||||
import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
|
||||
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
|
||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
|
||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||
|
@ -638,6 +639,9 @@ public class SessionView extends AbstractSessionView {
|
|||
}
|
||||
usersTable.setInput(users);
|
||||
usersTable.refresh();
|
||||
IMessage message = new TextMessage(participant, participant.getName()
|
||||
+ " has entered the room.");
|
||||
appendMessage(message);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -652,6 +656,9 @@ public class SessionView extends AbstractSessionView {
|
|||
break;
|
||||
}
|
||||
}
|
||||
IMessage message = new TextMessage(participant, participant.getName()
|
||||
+ " has left the room.");
|
||||
appendMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,7 @@ Export-Package: com.raytheon.viz.ui,
|
|||
com.raytheon.viz.ui.perspectives,
|
||||
com.raytheon.viz.ui.statusline,
|
||||
com.raytheon.viz.ui.tools,
|
||||
com.raytheon.viz.ui.views,
|
||||
com.raytheon.viz.ui.widgets
|
||||
Bundle-Vendor: Raytheon
|
||||
Import-Package: com.raytheon.uf.common.colormap,
|
||||
|
|
BIN
cave/com.raytheon.viz.ui/icons/float.gif
Normal file
BIN
cave/com.raytheon.viz.ui/icons/float.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 604 B |
|
@ -0,0 +1,527 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
|
||||
*******************************************************************************/
|
||||
|
||||
package com.raytheon.viz.ui.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.jface.util.Geometry;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ShellAdapter;
|
||||
import org.eclipse.swt.events.ShellEvent;
|
||||
import org.eclipse.swt.events.ShellListener;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IMemento;
|
||||
import org.eclipse.ui.IPropertyListener;
|
||||
import org.eclipse.ui.ISaveablePart;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.IViewReference;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchPartConstants;
|
||||
import org.eclipse.ui.IWorkbenchPartReference;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.contexts.IContextService;
|
||||
import org.eclipse.ui.internal.DetachedWindow;
|
||||
import org.eclipse.ui.internal.EditorManager;
|
||||
import org.eclipse.ui.internal.IWorkbenchConstants;
|
||||
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
|
||||
import org.eclipse.ui.internal.LayoutPart;
|
||||
import org.eclipse.ui.internal.PartPane;
|
||||
import org.eclipse.ui.internal.PartStack;
|
||||
import org.eclipse.ui.internal.ViewPane;
|
||||
import org.eclipse.ui.internal.ViewStack;
|
||||
import org.eclipse.ui.internal.WorkbenchPage;
|
||||
import org.eclipse.ui.internal.dnd.DragUtil;
|
||||
import org.eclipse.ui.internal.dnd.IDragOverListener;
|
||||
import org.eclipse.ui.internal.dnd.IDropTarget;
|
||||
import org.eclipse.ui.internal.presentations.PresentationFactoryUtil;
|
||||
import org.eclipse.ui.presentations.StackDropResult;
|
||||
|
||||
/**
|
||||
* TODO: Drag from detached to fast view bar back to detached causes NPE
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public class CaveDetachedWindow extends DetachedWindow implements
|
||||
IDragOverListener {
|
||||
|
||||
public static final int INFINITE = Integer.MAX_VALUE;
|
||||
|
||||
private ViewStack folder;
|
||||
|
||||
private WorkbenchPage page;
|
||||
|
||||
private Rectangle bounds = new Rectangle(0, 0, 0, 0);
|
||||
|
||||
private Shell windowShell;
|
||||
|
||||
private boolean hideViewsOnClose = true;
|
||||
|
||||
private ShellListener shellListener = new ShellAdapter() {
|
||||
public void shellClosed(ShellEvent e) {
|
||||
// only continue to close if the handleClose
|
||||
// wasn't canceled
|
||||
e.doit = handleClose();
|
||||
}
|
||||
};
|
||||
|
||||
private Listener resizeListener = new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
Shell shell = (Shell) event.widget;
|
||||
folder.setBounds(shell.getClientArea());
|
||||
}
|
||||
};
|
||||
|
||||
private IPropertyListener propertyListener = new IPropertyListener() {
|
||||
public void propertyChanged(Object source, int propId) {
|
||||
if (propId == PartStack.PROP_SELECTION) {
|
||||
activePartChanged(getPartReference(folder.getSelection()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private IWorkbenchPartReference activePart;
|
||||
|
||||
private IPropertyListener partPropertyListener = new IPropertyListener() {
|
||||
public void propertyChanged(Object source, int propId) {
|
||||
if (propId == IWorkbenchPartConstants.PROP_TITLE) {
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new FloatingWindow.
|
||||
*/
|
||||
public CaveDetachedWindow(WorkbenchPage workbenchPage) {
|
||||
super(workbenchPage);
|
||||
this.page = workbenchPage;
|
||||
|
||||
folder = new ViewStack(page, false, PresentationFactoryUtil.ROLE_VIEW,
|
||||
null);
|
||||
folder.addListener(propertyListener);
|
||||
}
|
||||
|
||||
protected void activePartChanged(IWorkbenchPartReference partReference) {
|
||||
if (activePart == partReference) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (activePart != null) {
|
||||
activePart.removePropertyListener(partPropertyListener);
|
||||
}
|
||||
activePart = partReference;
|
||||
if (partReference != null) {
|
||||
partReference.addPropertyListener(partPropertyListener);
|
||||
}
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
private void updateTitle() {
|
||||
if (activePart != null) {
|
||||
windowShell.setText(activePart.getPartName());
|
||||
// Uncomment to set the shell title to match the title of the active
|
||||
// part
|
||||
// String text = activePart.getTitle();
|
||||
//
|
||||
// if (!text.equals(s.getText())) {
|
||||
// s.setText(text);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the shell's minimum size is equal to the minimum size of the
|
||||
* first part added to the shell.
|
||||
*/
|
||||
private void updateMinimumSize() {
|
||||
// We can only do this for 'Tabbed' stacked presentations.
|
||||
|
||||
// Get the minimum space required for the part
|
||||
int width = folder.computePreferredSize(true, INFINITE, INFINITE, 0);
|
||||
int height = folder.computePreferredSize(false, INFINITE, INFINITE, 0);
|
||||
Rectangle bounds = folder.getChildren()[0].getControl().getBounds();
|
||||
|
||||
// Take the current shell 'trim' into account
|
||||
int shellHeight = windowShell.getBounds().height
|
||||
- windowShell.getClientArea().height;
|
||||
int shellWidth = windowShell.getBounds().width
|
||||
- windowShell.getClientArea().width;
|
||||
|
||||
windowShell.setMinimumSize(width + shellWidth, height + shellHeight);
|
||||
}
|
||||
|
||||
private static IWorkbenchPartReference getPartReference(PartPane pane) {
|
||||
|
||||
if (pane == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return pane.getPartReference();
|
||||
}
|
||||
|
||||
public Shell getShell() {
|
||||
return windowShell;
|
||||
}
|
||||
|
||||
public void create() {
|
||||
windowShell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM);
|
||||
windowShell.setData(this);
|
||||
windowShell.setText("Detached Window");
|
||||
DragUtil.addDragTarget(windowShell, this);
|
||||
hideViewsOnClose = true;
|
||||
if (bounds.isEmpty()) {
|
||||
Point center = Geometry.centerPoint(page.getWorkbenchWindow()
|
||||
.getShell().getBounds());
|
||||
Point size = new Point(300, 200);
|
||||
Point upperLeft = Geometry.subtract(center,
|
||||
Geometry.divide(size, 2));
|
||||
|
||||
bounds = Geometry.createRectangle(upperLeft, size);
|
||||
}
|
||||
|
||||
// Force the rect into the current display
|
||||
Rectangle dispBounds = getShell().getDisplay().getBounds();
|
||||
if (bounds.width > dispBounds.width)
|
||||
bounds.width = dispBounds.width;
|
||||
if (bounds.height > dispBounds.height)
|
||||
bounds.height = dispBounds.height;
|
||||
if (bounds.x + bounds.width > dispBounds.width)
|
||||
bounds.x = dispBounds.width - bounds.width;
|
||||
if (bounds.y + bounds.height > dispBounds.height)
|
||||
bounds.y = dispBounds.height - bounds.height;
|
||||
|
||||
getShell().setBounds(bounds);
|
||||
|
||||
configureShell(windowShell);
|
||||
|
||||
createContents(windowShell);
|
||||
windowShell.layout(true);
|
||||
folder.setBounds(windowShell.getClientArea());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a visual part to this window. Supports reparenting.
|
||||
*/
|
||||
public void add(ViewPane part) {
|
||||
|
||||
Shell shell = getShell();
|
||||
if (shell != null) {
|
||||
part.reparent(shell);
|
||||
}
|
||||
folder.add(part);
|
||||
updateMinimumSize();
|
||||
}
|
||||
|
||||
public boolean belongsToWorkbenchPage(IWorkbenchPage workbenchPage) {
|
||||
return (this.page == workbenchPage);
|
||||
}
|
||||
|
||||
public boolean close() {
|
||||
hideViewsOnClose = false;
|
||||
Shell shell = getShell();
|
||||
if (shell != null && !shell.isDisposed()) {
|
||||
shell.removeShellListener(shellListener);
|
||||
shell.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this window and disposes its shell.
|
||||
*/
|
||||
private boolean handleClose() {
|
||||
|
||||
if (hideViewsOnClose) {
|
||||
List views = new ArrayList();
|
||||
collectViewPanes(views, getChildren());
|
||||
|
||||
// Save any drty views
|
||||
if (!handleSaves(views)) {
|
||||
return false; // User canceled the save
|
||||
}
|
||||
|
||||
// OK, go on with the closing
|
||||
Iterator itr = views.iterator();
|
||||
while (itr.hasNext()) {
|
||||
ViewPane child = (ViewPane) itr.next();
|
||||
|
||||
// Only close if closable...
|
||||
if (child.isCloseable()) {
|
||||
page.hideView(child.getViewReference());
|
||||
|
||||
// Was the close cancelled?
|
||||
if (child.getContainer() != null)
|
||||
return false;
|
||||
} else {
|
||||
page.attachView(child.getViewReference());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (folder != null) {
|
||||
folder.dispose();
|
||||
}
|
||||
|
||||
if (windowShell != null) {
|
||||
windowShell.removeListener(SWT.Resize, resizeListener);
|
||||
DragUtil.removeDragTarget(windowShell, this);
|
||||
bounds = windowShell.getBounds();
|
||||
|
||||
// Unregister this detached view as a window (for key bindings).
|
||||
final IContextService contextService = (IContextService) getWorkbenchPage()
|
||||
.getWorkbenchWindow().getWorkbench()
|
||||
.getService(IContextService.class);
|
||||
contextService.unregisterShell(windowShell);
|
||||
|
||||
windowShell.setData(null);
|
||||
windowShell = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts for and handles the saving of dirty, saveable views
|
||||
*
|
||||
* @param views
|
||||
* The list of ViewPanes
|
||||
* @return <code>true</code> unless the user cancels the save(s)
|
||||
*/
|
||||
private boolean handleSaves(List views) {
|
||||
List dirtyViews = new ArrayList();
|
||||
for (Iterator iterator = views.iterator(); iterator.hasNext();) {
|
||||
ViewPane pane = (ViewPane) iterator.next();
|
||||
IViewReference ref = pane.getViewReference();
|
||||
IViewPart part = ref.getView(false);
|
||||
if (part instanceof ISaveablePart) {
|
||||
ISaveablePart saveable = (ISaveablePart) part;
|
||||
if (saveable.isDirty() && saveable.isSaveOnCloseNeeded()) {
|
||||
dirtyViews.add(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there are any prompt to save -before- any closing happens
|
||||
// FIXME: This code will result in a double prompt if the user
|
||||
// decides not to save a particular view at this stage they'll
|
||||
// get a second one from the 'hideView' call...
|
||||
if (dirtyViews.size() > 0) {
|
||||
IWorkbenchWindow window = page.getWorkbenchWindow();
|
||||
boolean success = EditorManager.saveAll(dirtyViews, true, true,
|
||||
false, window);
|
||||
if (!success) {
|
||||
return false; // the user canceled.
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void drop(PartPane sourcePart) {
|
||||
Rectangle displayBounds = DragUtil
|
||||
.getDisplayBounds(folder.getControl());
|
||||
IDropTarget target = folder.createDropTarget(sourcePart,
|
||||
new StackDropResult(displayBounds, null));
|
||||
target.drop();
|
||||
updateMinimumSize();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.internal.dnd.IDragOverListener#drag(org.eclipse.swt.widgets
|
||||
* .Control, java.lang.Object, org.eclipse.swt.graphics.Point,
|
||||
* org.eclipse.swt.graphics.Rectangle)
|
||||
*/
|
||||
public IDropTarget drag(Control currentControl, Object draggedObject,
|
||||
Point position, Rectangle dragRectangle) {
|
||||
|
||||
if (!(draggedObject instanceof PartPane)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final PartPane sourcePart = (PartPane) draggedObject;
|
||||
|
||||
if (sourcePart.getWorkbenchWindow() != page.getWorkbenchWindow()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only handle the event if the source part is acceptable to the
|
||||
// particular PartStack
|
||||
IDropTarget target = null;
|
||||
if (sourcePart instanceof ViewPane) {
|
||||
target = folder.getDropTarget(draggedObject, position);
|
||||
|
||||
if (target == null) {
|
||||
Rectangle displayBounds = DragUtil.getDisplayBounds(folder
|
||||
.getControl());
|
||||
if (displayBounds.contains(position)) {
|
||||
target = folder.createDropTarget(sourcePart,
|
||||
new StackDropResult(displayBounds, null));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer a list of the view panes.
|
||||
*/
|
||||
private void collectViewPanes(List result, LayoutPart[] parts) {
|
||||
for (int i = 0, length = parts.length; i < length; i++) {
|
||||
LayoutPart part = parts[i];
|
||||
if (part instanceof ViewPane) {
|
||||
result.add(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called to initialize the given Shell's layout
|
||||
*/
|
||||
protected void configureShell(Shell shell) {
|
||||
updateTitle();
|
||||
shell.addListener(SWT.Resize, resizeListener);
|
||||
|
||||
// Register this detached view as a window (for key bindings).
|
||||
final IContextService contextService = (IContextService) getWorkbenchPage()
|
||||
.getWorkbenchWindow().getWorkbench()
|
||||
.getService(IContextService.class);
|
||||
contextService.registerShell(shell, IContextService.TYPE_WINDOW);
|
||||
|
||||
page.getWorkbenchWindow().getWorkbench().getHelpSystem()
|
||||
.setHelp(shell, IWorkbenchHelpContextIds.DETACHED_WINDOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to create the widget tree that is used as the
|
||||
* window's contents.
|
||||
*/
|
||||
protected Control createContents(Composite parent) {
|
||||
// Create the tab folder.
|
||||
folder.createControl(parent);
|
||||
|
||||
// Reparent each view in the tab folder.
|
||||
Vector detachedChildren = new Vector();
|
||||
collectViewPanes(detachedChildren, getChildren());
|
||||
Enumeration itr = detachedChildren.elements();
|
||||
while (itr.hasMoreElements()) {
|
||||
LayoutPart part = (LayoutPart) itr.nextElement();
|
||||
part.reparent(parent);
|
||||
}
|
||||
|
||||
// Return tab folder control.
|
||||
return folder.getControl();
|
||||
}
|
||||
|
||||
public LayoutPart[] getChildren() {
|
||||
return folder.getChildren();
|
||||
}
|
||||
|
||||
public WorkbenchPage getWorkbenchPage() {
|
||||
return this.page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IPersistablePart
|
||||
*/
|
||||
public void restoreState(IMemento memento) {
|
||||
// Read the bounds.
|
||||
Integer bigInt;
|
||||
bigInt = memento.getInteger(IWorkbenchConstants.TAG_X);
|
||||
int x = bigInt.intValue();
|
||||
bigInt = memento.getInteger(IWorkbenchConstants.TAG_Y);
|
||||
int y = bigInt.intValue();
|
||||
bigInt = memento.getInteger(IWorkbenchConstants.TAG_WIDTH);
|
||||
int width = bigInt.intValue();
|
||||
bigInt = memento.getInteger(IWorkbenchConstants.TAG_HEIGHT);
|
||||
int height = bigInt.intValue();
|
||||
bigInt = memento.getInteger(IWorkbenchConstants.TAG_FLOAT);
|
||||
|
||||
// Set the bounds.
|
||||
bounds = new Rectangle(x, y, width, height);
|
||||
if (getShell() != null) {
|
||||
getShell().setBounds(bounds);
|
||||
}
|
||||
|
||||
// Create the folder.
|
||||
IMemento childMem = memento.getChild(IWorkbenchConstants.TAG_FOLDER);
|
||||
if (childMem != null) {
|
||||
folder.restoreState(childMem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IPersistablePart
|
||||
*/
|
||||
public void saveState(IMemento memento) {
|
||||
if (getShell() != null) {
|
||||
bounds = getShell().getBounds();
|
||||
}
|
||||
|
||||
// Save the bounds.
|
||||
memento.putInteger(IWorkbenchConstants.TAG_X, bounds.x);
|
||||
memento.putInteger(IWorkbenchConstants.TAG_Y, bounds.y);
|
||||
memento.putInteger(IWorkbenchConstants.TAG_WIDTH, bounds.width);
|
||||
memento.putInteger(IWorkbenchConstants.TAG_HEIGHT, bounds.height);
|
||||
|
||||
// Save the views.
|
||||
IMemento childMem = memento.createChild(IWorkbenchConstants.TAG_FOLDER);
|
||||
folder.saveState(childMem);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.ui.internal.IWorkbenchDragDropPart#getControl()
|
||||
*/
|
||||
public Control getControl() {
|
||||
return folder.getControl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the detached window.
|
||||
*/
|
||||
public int open() {
|
||||
|
||||
if (getShell() == null) {
|
||||
create();
|
||||
}
|
||||
|
||||
Rectangle bounds = getShell().getBounds();
|
||||
getShell().setVisible(true);
|
||||
|
||||
if (!bounds.equals(getShell().getBounds())) {
|
||||
getShell().setBounds(bounds);
|
||||
}
|
||||
|
||||
return Window.OK;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.viz.ui.views;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.internal.ILayoutContainer;
|
||||
import org.eclipse.ui.internal.PartPane;
|
||||
import org.eclipse.ui.internal.PartPlaceholder;
|
||||
import org.eclipse.ui.internal.ViewPane;
|
||||
import org.eclipse.ui.internal.ViewSite;
|
||||
import org.eclipse.ui.internal.WorkbenchPage;
|
||||
import org.eclipse.ui.internal.dnd.DragUtil;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
import com.raytheon.viz.ui.UiPlugin;
|
||||
|
||||
/**
|
||||
* Creates the ability to have a dialog that can be minimized and maximized and
|
||||
* is separate from the original CAVE window from a view
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* May 22, 2012 mnash Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mnash
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public abstract class CaveFloatingView extends ViewPart {
|
||||
|
||||
private boolean detached;
|
||||
|
||||
private CaveDetachedWindow window;
|
||||
|
||||
private ILayoutContainer container;
|
||||
|
||||
private Rectangle bounds;
|
||||
|
||||
/**
|
||||
* Constructs the view
|
||||
*/
|
||||
public CaveFloatingView() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(final Composite parent) {
|
||||
createToolbarButton();
|
||||
}
|
||||
|
||||
public IViewPart getPart() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the "Float" toolbar button
|
||||
*/
|
||||
protected void createToolbarButton() {
|
||||
IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
|
||||
Action floatAction = new Action("Float", SWT.TOGGLE) {
|
||||
@Override
|
||||
public void run() {
|
||||
// should only run when the user is currently attached to cave
|
||||
// (or detached, but not a floating dialog)
|
||||
detached = true;
|
||||
WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow().getActivePage();
|
||||
bounds = ((ViewSite) ((ViewPart) getPart()).getViewSite())
|
||||
.getPane().getBounds();
|
||||
container = ((ViewSite) ((ViewPart) getPart()).getViewSite())
|
||||
.getPane().getStack();
|
||||
container.add(new PartPlaceholder("temp "));
|
||||
window = new CaveDetachedWindow(page);
|
||||
window.create();
|
||||
window.open();
|
||||
|
||||
ViewPane pane = (ViewPane) ((ViewSite) getPart().getViewSite())
|
||||
.getPane();
|
||||
container = pane.getContainer();
|
||||
window.drop(pane);
|
||||
window.getShell().setBounds(bounds);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void runWithEvent(Event event) {
|
||||
if (!detached) {
|
||||
run();
|
||||
return;
|
||||
}
|
||||
detached = false;
|
||||
WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow().getActivePage();
|
||||
PartPane layoutPart = ((ViewSite) getPart().getViewSite())
|
||||
.getPane();
|
||||
Point point = new Point(bounds.x + bounds.width / 2, bounds.y
|
||||
+ bounds.height / 2);
|
||||
window.getShell().setVisible(false);
|
||||
DragUtil.dragTo(Display.getCurrent(), layoutPart, point, bounds);
|
||||
}
|
||||
};
|
||||
floatAction.setImageDescriptor(UiPlugin.getImageDescriptor("icons"
|
||||
+ File.separator + "float.gif"));
|
||||
mgr.add(floatAction);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue