diff options
Diffstat (limited to 'plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views')
7 files changed, 1133 insertions, 1133 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java index 141bff1457..0b8d31b5a6 100644 --- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java +++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDragListener.java @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.buddies.internal.ui.views; - -import org.eclipse.net4j.buddies.common.IBuddy; -import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer; -import org.eclipse.net4j.util.ui.dnd.DNDDragListener; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.Transfer; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -/** - * @author Eike Stepper - */ -public class BuddiesDragListener extends DNDDragListener<IBuddy[]> -{ - private static final Transfer[] TRANSFERS = new Transfer[] { BuddiesTransfer.INSTANCE }; - - protected BuddiesDragListener(StructuredViewer viewer) - { - super(TRANSFERS, viewer); - } - - @Override - protected IBuddy[] getObject(IStructuredSelection selection) - { - Collection<IBuddy> buddies = new ArrayList<IBuddy>(); - for (Iterator<?> it = selection.iterator(); it.hasNext();) - { - Object element = it.next(); - if (element instanceof IBuddy) - { - IBuddy buddy = (IBuddy)element; - buddies.add(buddy); - } - } - - if (buddies.isEmpty()) - { - return null; - } - - return buddies.toArray(new IBuddy[buddies.size()]); - } - - public static void support(StructuredViewer viewer) - { - viewer.addDragSupport(DND.DROP_MOVE, TRANSFERS, new BuddiesDragListener(viewer)); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer;
+import org.eclipse.net4j.util.ui.dnd.DNDDragListener;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddiesDragListener extends DNDDragListener<IBuddy[]>
+{
+ private static final Transfer[] TRANSFERS = new Transfer[] { BuddiesTransfer.INSTANCE };
+
+ protected BuddiesDragListener(StructuredViewer viewer)
+ {
+ super(TRANSFERS, viewer);
+ }
+
+ @Override
+ protected IBuddy[] getObject(IStructuredSelection selection)
+ {
+ Collection<IBuddy> buddies = new ArrayList<IBuddy>();
+ for (Iterator<?> it = selection.iterator(); it.hasNext();)
+ {
+ Object element = it.next();
+ if (element instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)element;
+ buddies.add(buddy);
+ }
+ }
+
+ if (buddies.isEmpty())
+ {
+ return null;
+ }
+
+ return buddies.toArray(new IBuddy[buddies.size()]);
+ }
+
+ public static void support(StructuredViewer viewer)
+ {
+ viewer.addDragSupport(DND.DROP_MOVE, TRANSFERS, new BuddiesDragListener(viewer));
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDropAdapter.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDropAdapter.java index 0b57b684e3..d4b3062e2a 100644 --- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDropAdapter.java +++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesDropAdapter.java @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.buddies.internal.ui.views; - -import org.eclipse.net4j.buddies.IBuddyCollaboration; -import org.eclipse.net4j.buddies.common.IBuddy; -import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer; -import org.eclipse.net4j.util.ui.dnd.DNDDropAdapter; - -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.Transfer; - -/** - * @author Eike Stepper - */ -public class BuddiesDropAdapter extends DNDDropAdapter<IBuddy[]> -{ - /** - * @since 3.0 - */ - public static final Transfer[] TRANSFERS = new Transfer[] { BuddiesTransfer.INSTANCE }; - - protected BuddiesDropAdapter(StructuredViewer viewer) - { - super(TRANSFERS, viewer); - setExpandEnabled(false); - } - - @Override - protected boolean validateTarget(Object target, int operation) - { - return target instanceof IBuddyCollaboration; - } - - @Override - protected boolean performDrop(IBuddy[] buddies, Object target) - { - IBuddyCollaboration collaboration = (IBuddyCollaboration)target; - collaboration.invite(buddies); - return true; - } - - public static void support(StructuredViewer viewer) - { - viewer.addDropSupport(DND.DROP_MOVE, TRANSFERS, new BuddiesDropAdapter(viewer)); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.internal.ui.dnd.BuddiesTransfer;
+import org.eclipse.net4j.util.ui.dnd.DNDDropAdapter;
+
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddiesDropAdapter extends DNDDropAdapter<IBuddy[]>
+{
+ /**
+ * @since 3.0
+ */
+ public static final Transfer[] TRANSFERS = new Transfer[] { BuddiesTransfer.INSTANCE };
+
+ protected BuddiesDropAdapter(StructuredViewer viewer)
+ {
+ super(TRANSFERS, viewer);
+ setExpandEnabled(false);
+ }
+
+ @Override
+ protected boolean validateTarget(Object target, int operation)
+ {
+ return target instanceof IBuddyCollaboration;
+ }
+
+ @Override
+ protected boolean performDrop(IBuddy[] buddies, Object target)
+ {
+ IBuddyCollaboration collaboration = (IBuddyCollaboration)target;
+ collaboration.invite(buddies);
+ return true;
+ }
+
+ public static void support(StructuredViewer viewer)
+ {
+ viewer.addDropSupport(DND.DROP_MOVE, TRANSFERS, new BuddiesDropAdapter(viewer));
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java index 70dbfbf640..68099e144e 100644 --- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java +++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.buddies.internal.ui.views; - -import org.eclipse.net4j.buddies.IBuddyCollaboration; -import org.eclipse.net4j.buddies.common.IBuddy; -import org.eclipse.net4j.buddies.common.IMembership; -import org.eclipse.net4j.buddies.internal.ui.ChatInstaller; -import org.eclipse.net4j.util.container.ContainerUtil; -import org.eclipse.net4j.util.container.IContainer; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -public class BuddiesView extends SessionManagerView -{ - public BuddiesView() - { - } - - @Override - protected IContainer<?> getContainer() - { - return getSession() != null ? getSession() : ContainerUtil.emptyContainer(); - } - - @Override - protected Control createControl(Composite parent) - { - Control control = super.createControl(parent); - BuddiesDragListener.support(getViewer()); - BuddiesDropAdapter.support(getViewer()); - return control; - } - - @Override - protected void doubleClicked(Object object) - { - if (getSession() != null && object instanceof IBuddy) - { - IBuddy buddy = (IBuddy)object; - IBuddy self = getSession().getSelf(); - IMembership membership = self.initiate(buddy); - - try - { - // The chat dependency is optional - ChatInstaller.installChat((IBuddyCollaboration)membership.getCollaboration()); - } - catch (Throwable ignore) - { - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.common.IBuddy;
+import org.eclipse.net4j.buddies.common.IMembership;
+import org.eclipse.net4j.buddies.internal.ui.ChatInstaller;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IContainer;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public class BuddiesView extends SessionManagerView
+{
+ public BuddiesView()
+ {
+ }
+
+ @Override
+ protected IContainer<?> getContainer()
+ {
+ return getSession() != null ? getSession() : ContainerUtil.emptyContainer();
+ }
+
+ @Override
+ protected Control createControl(Composite parent)
+ {
+ Control control = super.createControl(parent);
+ BuddiesDragListener.support(getViewer());
+ BuddiesDropAdapter.support(getViewer());
+ return control;
+ }
+
+ @Override
+ protected void doubleClicked(Object object)
+ {
+ if (getSession() != null && object instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)object;
+ IBuddy self = getSession().getSelf();
+ IMembership membership = self.initiate(buddy);
+
+ try
+ {
+ // The chat dependency is optional
+ ChatInstaller.installChat((IBuddyCollaboration)membership.getCollaboration());
+ }
+ catch (Throwable ignore)
+ {
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java index 679af3754a..3be3363beb 100644 --- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java +++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java @@ -1,334 +1,334 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.buddies.internal.ui.views; - -import org.eclipse.net4j.buddies.IBuddyCollaboration; -import org.eclipse.net4j.buddies.IBuddySession; -import org.eclipse.net4j.buddies.common.ICollaboration; -import org.eclipse.net4j.buddies.common.IFacility; -import org.eclipse.net4j.buddies.common.IFacilityInstalledEvent; -import org.eclipse.net4j.buddies.common.IMembership; -import org.eclipse.net4j.buddies.internal.ui.messages.Messages; -import org.eclipse.net4j.buddies.ui.IFacilityPaneCreator; -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.StringUtil; -import org.eclipse.net4j.util.container.IContainerEvent; -import org.eclipse.net4j.util.container.IContainerEventVisitor; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.ui.actions.SafeAction; - -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IActionBars; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Eike Stepper - */ -public class CollaborationsPane extends Composite implements IListener -{ - private CollaborationsView collaborationsView; - - private IBuddySession session; - - private IBuddyCollaboration activeCollaboration; - - private Map<IBuddyCollaboration, IFacility> activeFacilities = new HashMap<IBuddyCollaboration, IFacility>(); - - private Map<IFacility, FacilityPane> facilityPanes = new HashMap<IFacility, FacilityPane>(); - - private List<ActivateFacilityAction> activateFacilityActions = new ArrayList<ActivateFacilityAction>(); - - private StackLayout paneStack; - - public CollaborationsPane(Composite parent, CollaborationsView collaborationsView) - { - super(parent, SWT.NONE); - setLayout(paneStack = new StackLayout()); - this.collaborationsView = collaborationsView; - } - - public CollaborationsView getCollaborationsView() - { - return collaborationsView; - } - - public IBuddySession getSession() - { - return session; - } - - public void setSession(IBuddySession session) - { - this.session = session; - if (session != null) - { - for (ICollaboration collaboration : session.getSelf().getCollaborations()) - { - collaborationAdded((IBuddyCollaboration)collaboration); - } - } - - updateState(); - } - - public IBuddyCollaboration getActiveCollaboration() - { - return activeCollaboration; - } - - public void setActiveCollaboration(IBuddyCollaboration collaboration) - { - if (activeCollaboration != collaboration) - { - activeCollaboration = collaboration; - IFacility facility = activeFacilities.get(collaboration); - setActiveFacility(collaboration, facility); - updateState(); - collaborationsView.refreshViewer(true); - } - } - - public void setActiveFacility(IBuddyCollaboration collaboration, IFacility facility) - { - activeFacilities.put(collaboration, facility); - if (collaboration == activeCollaboration) - { - FacilityPane facilityPane = facilityPanes.get(facility); - setActiveFacilityPane(facilityPane); - updateState(); - } - } - - protected void setActiveFacilityPane(FacilityPane newPane) - { - if (paneStack.topControl != newPane) - { - FacilityPane oldPane = (FacilityPane)paneStack.topControl; - if (oldPane != null) - { - oldPane.hidden(newPane); - } - - paneStack.topControl = newPane; - layout(); - if (newPane != null) - { - newPane.showed(oldPane); - } - - updateState(); - } - } - - public void fillActionBars(IActionBars bars) - { - IToolBarManager manager = bars.getToolBarManager(); - for (IFacilityPaneCreator c : collaborationsView.getFacilityPaneCreators().values()) - { - ActivateFacilityAction action = new ActivateFacilityAction(c.getType(), c.getImageDescriptor()); - activateFacilityActions.add(action); - manager.add(action); - } - } - - public void updateState() - { - for (ActivateFacilityAction action : activateFacilityActions) - { - if (activeCollaboration == null) - { - action.setEnabled(false); - } - else - { - String type = action.getType(); - action.setEnabled(activeCollaboration.getFacility(type) != null); - - IFacility activeFacility = activeFacilities.get(activeCollaboration); - action.setChecked(activeFacility != null && ObjectUtil.equals(activeFacility.getType(), type)); - } - } - } - - public void notifyEvent(IEvent event) - { - if (session == null) - { - return; - } - - if (event.getSource() == session.getSelf() && event instanceof IContainerEvent<?>) - { - @SuppressWarnings("unchecked") - IContainerEvent<IMembership> e = (IContainerEvent<IMembership>)event; - e.accept(new IContainerEventVisitor<IMembership>() - { - public void added(IMembership membership) - { - collaborationAdded((IBuddyCollaboration)membership.getCollaboration()); - } - - public void removed(IMembership membership) - { - collaborationRemoved((IBuddyCollaboration)membership.getCollaboration()); - } - }); - } - else if (event instanceof IFacilityInstalledEvent) - { - IFacilityInstalledEvent e = (IFacilityInstalledEvent)event; - facilityInstalled(e.getFacility(), e.fromRemote()); - } - } - - protected void collaborationAdded(IBuddyCollaboration collaboration) - { - IFacility[] facilities = collaboration.getFacilities(); - for (IFacility facility : facilities) - { - addFacilityPane(facility); - } - - if (activeCollaboration == null) - { - setActiveCollaboration(collaboration); - } - - if (facilities.length != 0) - { - setActiveFacility(collaboration, facilities[0]); - } - - collaboration.addListener(this); - } - - protected void collaborationRemoved(IBuddyCollaboration collaboration) - { - collaboration.removeListener(this); - if (activeCollaboration == collaboration) - { - setActiveCollaboration(activeFacilities.isEmpty() ? null : activeFacilities.keySet().iterator().next()); - } - - activeFacilities.remove(collaboration); - for (IFacility facility : collaboration.getFacilities()) - { - FacilityPane pane = facilityPanes.remove(facility); - if (pane != null) - { - pane.dispose(); - } - } - } - - protected void facilityInstalled(final IFacility facility, boolean fromRemote) - { - final IBuddyCollaboration collaboration = (IBuddyCollaboration)facility.getCollaboration(); - if (fromRemote) - { - Runnable runnable = new Runnable() - { - public void run() - { - try - { - addFacilityPane(facility); - IFacility activeFacility = activeFacilities.get(collaboration); - if (activeFacility == null) - { - setActiveFacility(collaboration, facility); - } - else - { - updateState(); - } - } - catch (RuntimeException ignore) - { - } - } - }; - - try - { - Display display = getDisplay(); - if (display.getThread() == Thread.currentThread()) - { - runnable.run(); - } - else - { - display.asyncExec(runnable); - } - } - catch (RuntimeException ignore) - { - } - } - else - { - addFacilityPane(facility); - setActiveCollaboration(collaboration); - setActiveFacility(collaboration, facility); - } - } - - protected FacilityPane addFacilityPane(IFacility facility) - { - IFacilityPaneCreator creator = collaborationsView.getFacilityPaneCreators().get(facility.getType()); - FacilityPane pane = creator.createPane(this, SWT.NONE); - pane.setFacility(facility); - facilityPanes.put(facility, pane); - return pane; - } - - /** - * @author Eike Stepper - */ - private final class ActivateFacilityAction extends SafeAction - { - private final String type; - - private ActivateFacilityAction(String type, ImageDescriptor descriptor) - { - super(StringUtil.cap(type), AS_RADIO_BUTTON); - setToolTipText(MessageFormat.format(Messages.getString("CollaborationsPane_0"), type)); //$NON-NLS-1$ - setImageDescriptor(descriptor); - this.type = type; - } - - public String getType() - { - return type; - } - - @Override - protected void safeRun() throws Exception - { - if (activeCollaboration != null) - { - IFacility facility = activeCollaboration.getFacility(type); - setActiveFacility(activeCollaboration, facility); - } - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.common.ICollaboration;
+import org.eclipse.net4j.buddies.common.IFacility;
+import org.eclipse.net4j.buddies.common.IFacilityInstalledEvent;
+import org.eclipse.net4j.buddies.common.IMembership;
+import org.eclipse.net4j.buddies.internal.ui.messages.Messages;
+import org.eclipse.net4j.buddies.ui.IFacilityPaneCreator;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.container.IContainerEvent;
+import org.eclipse.net4j.util.container.IContainerEventVisitor;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.ui.actions.SafeAction;
+
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IActionBars;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class CollaborationsPane extends Composite implements IListener
+{
+ private CollaborationsView collaborationsView;
+
+ private IBuddySession session;
+
+ private IBuddyCollaboration activeCollaboration;
+
+ private Map<IBuddyCollaboration, IFacility> activeFacilities = new HashMap<IBuddyCollaboration, IFacility>();
+
+ private Map<IFacility, FacilityPane> facilityPanes = new HashMap<IFacility, FacilityPane>();
+
+ private List<ActivateFacilityAction> activateFacilityActions = new ArrayList<ActivateFacilityAction>();
+
+ private StackLayout paneStack;
+
+ public CollaborationsPane(Composite parent, CollaborationsView collaborationsView)
+ {
+ super(parent, SWT.NONE);
+ setLayout(paneStack = new StackLayout());
+ this.collaborationsView = collaborationsView;
+ }
+
+ public CollaborationsView getCollaborationsView()
+ {
+ return collaborationsView;
+ }
+
+ public IBuddySession getSession()
+ {
+ return session;
+ }
+
+ public void setSession(IBuddySession session)
+ {
+ this.session = session;
+ if (session != null)
+ {
+ for (ICollaboration collaboration : session.getSelf().getCollaborations())
+ {
+ collaborationAdded((IBuddyCollaboration)collaboration);
+ }
+ }
+
+ updateState();
+ }
+
+ public IBuddyCollaboration getActiveCollaboration()
+ {
+ return activeCollaboration;
+ }
+
+ public void setActiveCollaboration(IBuddyCollaboration collaboration)
+ {
+ if (activeCollaboration != collaboration)
+ {
+ activeCollaboration = collaboration;
+ IFacility facility = activeFacilities.get(collaboration);
+ setActiveFacility(collaboration, facility);
+ updateState();
+ collaborationsView.refreshViewer(true);
+ }
+ }
+
+ public void setActiveFacility(IBuddyCollaboration collaboration, IFacility facility)
+ {
+ activeFacilities.put(collaboration, facility);
+ if (collaboration == activeCollaboration)
+ {
+ FacilityPane facilityPane = facilityPanes.get(facility);
+ setActiveFacilityPane(facilityPane);
+ updateState();
+ }
+ }
+
+ protected void setActiveFacilityPane(FacilityPane newPane)
+ {
+ if (paneStack.topControl != newPane)
+ {
+ FacilityPane oldPane = (FacilityPane)paneStack.topControl;
+ if (oldPane != null)
+ {
+ oldPane.hidden(newPane);
+ }
+
+ paneStack.topControl = newPane;
+ layout();
+ if (newPane != null)
+ {
+ newPane.showed(oldPane);
+ }
+
+ updateState();
+ }
+ }
+
+ public void fillActionBars(IActionBars bars)
+ {
+ IToolBarManager manager = bars.getToolBarManager();
+ for (IFacilityPaneCreator c : collaborationsView.getFacilityPaneCreators().values())
+ {
+ ActivateFacilityAction action = new ActivateFacilityAction(c.getType(), c.getImageDescriptor());
+ activateFacilityActions.add(action);
+ manager.add(action);
+ }
+ }
+
+ public void updateState()
+ {
+ for (ActivateFacilityAction action : activateFacilityActions)
+ {
+ if (activeCollaboration == null)
+ {
+ action.setEnabled(false);
+ }
+ else
+ {
+ String type = action.getType();
+ action.setEnabled(activeCollaboration.getFacility(type) != null);
+
+ IFacility activeFacility = activeFacilities.get(activeCollaboration);
+ action.setChecked(activeFacility != null && ObjectUtil.equals(activeFacility.getType(), type));
+ }
+ }
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (session == null)
+ {
+ return;
+ }
+
+ if (event.getSource() == session.getSelf() && event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IMembership> e = (IContainerEvent<IMembership>)event;
+ e.accept(new IContainerEventVisitor<IMembership>()
+ {
+ public void added(IMembership membership)
+ {
+ collaborationAdded((IBuddyCollaboration)membership.getCollaboration());
+ }
+
+ public void removed(IMembership membership)
+ {
+ collaborationRemoved((IBuddyCollaboration)membership.getCollaboration());
+ }
+ });
+ }
+ else if (event instanceof IFacilityInstalledEvent)
+ {
+ IFacilityInstalledEvent e = (IFacilityInstalledEvent)event;
+ facilityInstalled(e.getFacility(), e.fromRemote());
+ }
+ }
+
+ protected void collaborationAdded(IBuddyCollaboration collaboration)
+ {
+ IFacility[] facilities = collaboration.getFacilities();
+ for (IFacility facility : facilities)
+ {
+ addFacilityPane(facility);
+ }
+
+ if (activeCollaboration == null)
+ {
+ setActiveCollaboration(collaboration);
+ }
+
+ if (facilities.length != 0)
+ {
+ setActiveFacility(collaboration, facilities[0]);
+ }
+
+ collaboration.addListener(this);
+ }
+
+ protected void collaborationRemoved(IBuddyCollaboration collaboration)
+ {
+ collaboration.removeListener(this);
+ if (activeCollaboration == collaboration)
+ {
+ setActiveCollaboration(activeFacilities.isEmpty() ? null : activeFacilities.keySet().iterator().next());
+ }
+
+ activeFacilities.remove(collaboration);
+ for (IFacility facility : collaboration.getFacilities())
+ {
+ FacilityPane pane = facilityPanes.remove(facility);
+ if (pane != null)
+ {
+ pane.dispose();
+ }
+ }
+ }
+
+ protected void facilityInstalled(final IFacility facility, boolean fromRemote)
+ {
+ final IBuddyCollaboration collaboration = (IBuddyCollaboration)facility.getCollaboration();
+ if (fromRemote)
+ {
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ addFacilityPane(facility);
+ IFacility activeFacility = activeFacilities.get(collaboration);
+ if (activeFacility == null)
+ {
+ setActiveFacility(collaboration, facility);
+ }
+ else
+ {
+ updateState();
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ };
+
+ try
+ {
+ Display display = getDisplay();
+ if (display.getThread() == Thread.currentThread())
+ {
+ runnable.run();
+ }
+ else
+ {
+ display.asyncExec(runnable);
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ else
+ {
+ addFacilityPane(facility);
+ setActiveCollaboration(collaboration);
+ setActiveFacility(collaboration, facility);
+ }
+ }
+
+ protected FacilityPane addFacilityPane(IFacility facility)
+ {
+ IFacilityPaneCreator creator = collaborationsView.getFacilityPaneCreators().get(facility.getType());
+ FacilityPane pane = creator.createPane(this, SWT.NONE);
+ pane.setFacility(facility);
+ facilityPanes.put(facility, pane);
+ return pane;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class ActivateFacilityAction extends SafeAction
+ {
+ private final String type;
+
+ private ActivateFacilityAction(String type, ImageDescriptor descriptor)
+ {
+ super(StringUtil.cap(type), AS_RADIO_BUTTON);
+ setToolTipText(MessageFormat.format(Messages.getString("CollaborationsPane_0"), type)); //$NON-NLS-1$
+ setImageDescriptor(descriptor);
+ this.type = type;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ @Override
+ protected void safeRun() throws Exception
+ {
+ if (activeCollaboration != null)
+ {
+ IFacility facility = activeCollaboration.getFacility(type);
+ setActiveFacility(activeCollaboration, facility);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java index caca1be295..30244a6900 100644 --- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java +++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java @@ -1,221 +1,221 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.buddies.internal.ui.views; - -import org.eclipse.net4j.buddies.IBuddyCollaboration; -import org.eclipse.net4j.buddies.internal.ui.CollaborationsItemProvider; -import org.eclipse.net4j.buddies.internal.ui.bundle.OM; -import org.eclipse.net4j.buddies.internal.ui.messages.Messages; -import org.eclipse.net4j.buddies.ui.IFacilityPaneCreator; -import org.eclipse.net4j.util.StringUtil; -import org.eclipse.net4j.util.container.ContainerUtil; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.ui.actions.SafeAction; -import org.eclipse.net4j.util.ui.actions.SashLayoutAction; -import org.eclipse.net4j.util.ui.views.ContainerItemProvider; -import org.eclipse.net4j.util.ui.widgets.SashComposite; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchActionConstants; - -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - -public class CollaborationsView extends SessionManagerView -{ - private SashComposite sashComposite; - - private Map<String, IFacilityPaneCreator> facilityPaneCreators = new HashMap<String, IFacilityPaneCreator>(); - - public CollaborationsView() - { - initFacilityPaneCreators(); - } - - public CollaborationsPane getCollaborationsPane() - { - return (CollaborationsPane)sashComposite.getControl2(); - } - - public Map<String, IFacilityPaneCreator> getFacilityPaneCreators() - { - return facilityPaneCreators; - } - - @Override - protected Control createControl(Composite parent) - { - sashComposite = new SashComposite(parent, SWT.NONE, 10, 30) - { - @Override - protected Control createControl1(Composite parent) - { - return CollaborationsView.super.createControl(parent); - } - - @Override - protected Control createControl2(Composite parent) - { - return new CollaborationsPane(parent, CollaborationsView.this); - } - }; - - IActionBars bars = getViewSite().getActionBars(); - bars.getMenuManager().add(new Separator()); - bars.getToolBarManager().add(new Separator()); - getCollaborationsPane().fillActionBars(bars); - - BuddiesDropAdapter.support(getViewer()); - return sashComposite; - } - - @Override - protected void queryBuddiesManager() - { - super.queryBuddiesManager(); - getCollaborationsPane().setSession(getSession()); - } - - @Override - public void notifyEvent(IEvent event) - { - super.notifyEvent(event); - getCollaborationsPane().notifyEvent(event); - } - - @Override - protected void fillLocalPullDown(IMenuManager manager) - { - super.fillLocalPullDown(manager); - manager.add(new Separator()); - manager.add(new SashLayoutAction.LayoutMenu(sashComposite)); - } - - @Override - protected void fillContextMenu(IMenuManager manager, ITreeSelection selection) - { - super.fillContextMenu(manager, selection); - if (selection.size() == 1) - { - final IBuddyCollaboration collaboration = (IBuddyCollaboration)selection.getFirstElement(); - if (collaboration != null) - { - manager.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, new Separator()); - for (IFacilityPaneCreator c : facilityPaneCreators.values()) - { - String type = c.getType(); - if (collaboration.getFacility(type) == null) - { - IAction action = new StartFacilityAction(collaboration, type, c.getImageDescriptor()); - manager.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, action); - } - } - } - } - } - - @Override - protected void doubleClicked(Object object) - { - if (object instanceof IBuddyCollaboration) - { - IBuddyCollaboration collaboration = (IBuddyCollaboration)object; - getCollaborationsPane().setActiveCollaboration(collaboration); - } - } - - @Override - protected IContainer<?> getContainer() - { - return getSession() != null ? getSession().getSelf() : ContainerUtil.emptyContainer(); - } - - @Override - protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider() - { - return new CollaborationsItemProvider() - { - @Override - public Font getFont(Object obj) - { - if (obj instanceof IBuddyCollaboration) - { - if (obj == getCollaborationsPane().getActiveCollaboration()) - { - return getBold(); - } - } - - return super.getFont(obj); - } - }; - } - - protected void initFacilityPaneCreators() - { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, OM.EXT_POINT); - for (final IConfigurationElement element : elements) - { - if ("facilityPaneCreator".equals(element.getName())) //$NON-NLS-1$ - { - try - { - IFacilityPaneCreator creator = (IFacilityPaneCreator)element.createExecutableExtension("class"); //$NON-NLS-1$ - facilityPaneCreators.put(creator.getType(), creator); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - } - } - } - - /** - * @author Eike Stepper - */ - private final class StartFacilityAction extends SafeAction - { - private final String type; - - private IBuddyCollaboration collaboration; - - private StartFacilityAction(IBuddyCollaboration collaboration, String type, ImageDescriptor descriptor) - { - super(MessageFormat.format(Messages.getString("CollaborationsView_2"), StringUtil.cap(type)), AS_RADIO_BUTTON); //$NON-NLS-1$ - setToolTipText(MessageFormat.format(Messages.getString("CollaborationsView_3"), type)); //$NON-NLS-1$ - setImageDescriptor(descriptor); - this.collaboration = collaboration; - this.type = type; - } - - @Override - protected void safeRun() throws Exception - { - collaboration.installFacility(type); - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.internal.ui.CollaborationsItemProvider;
+import org.eclipse.net4j.buddies.internal.ui.bundle.OM;
+import org.eclipse.net4j.buddies.internal.ui.messages.Messages;
+import org.eclipse.net4j.buddies.ui.IFacilityPaneCreator;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.ui.actions.SafeAction;
+import org.eclipse.net4j.util.ui.actions.SashLayoutAction;
+import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
+import org.eclipse.net4j.util.ui.widgets.SashComposite;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+public class CollaborationsView extends SessionManagerView
+{
+ private SashComposite sashComposite;
+
+ private Map<String, IFacilityPaneCreator> facilityPaneCreators = new HashMap<String, IFacilityPaneCreator>();
+
+ public CollaborationsView()
+ {
+ initFacilityPaneCreators();
+ }
+
+ public CollaborationsPane getCollaborationsPane()
+ {
+ return (CollaborationsPane)sashComposite.getControl2();
+ }
+
+ public Map<String, IFacilityPaneCreator> getFacilityPaneCreators()
+ {
+ return facilityPaneCreators;
+ }
+
+ @Override
+ protected Control createControl(Composite parent)
+ {
+ sashComposite = new SashComposite(parent, SWT.NONE, 10, 30)
+ {
+ @Override
+ protected Control createControl1(Composite parent)
+ {
+ return CollaborationsView.super.createControl(parent);
+ }
+
+ @Override
+ protected Control createControl2(Composite parent)
+ {
+ return new CollaborationsPane(parent, CollaborationsView.this);
+ }
+ };
+
+ IActionBars bars = getViewSite().getActionBars();
+ bars.getMenuManager().add(new Separator());
+ bars.getToolBarManager().add(new Separator());
+ getCollaborationsPane().fillActionBars(bars);
+
+ BuddiesDropAdapter.support(getViewer());
+ return sashComposite;
+ }
+
+ @Override
+ protected void queryBuddiesManager()
+ {
+ super.queryBuddiesManager();
+ getCollaborationsPane().setSession(getSession());
+ }
+
+ @Override
+ public void notifyEvent(IEvent event)
+ {
+ super.notifyEvent(event);
+ getCollaborationsPane().notifyEvent(event);
+ }
+
+ @Override
+ protected void fillLocalPullDown(IMenuManager manager)
+ {
+ super.fillLocalPullDown(manager);
+ manager.add(new Separator());
+ manager.add(new SashLayoutAction.LayoutMenu(sashComposite));
+ }
+
+ @Override
+ protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
+ {
+ super.fillContextMenu(manager, selection);
+ if (selection.size() == 1)
+ {
+ final IBuddyCollaboration collaboration = (IBuddyCollaboration)selection.getFirstElement();
+ if (collaboration != null)
+ {
+ manager.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, new Separator());
+ for (IFacilityPaneCreator c : facilityPaneCreators.values())
+ {
+ String type = c.getType();
+ if (collaboration.getFacility(type) == null)
+ {
+ IAction action = new StartFacilityAction(collaboration, type, c.getImageDescriptor());
+ manager.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, action);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void doubleClicked(Object object)
+ {
+ if (object instanceof IBuddyCollaboration)
+ {
+ IBuddyCollaboration collaboration = (IBuddyCollaboration)object;
+ getCollaborationsPane().setActiveCollaboration(collaboration);
+ }
+ }
+
+ @Override
+ protected IContainer<?> getContainer()
+ {
+ return getSession() != null ? getSession().getSelf() : ContainerUtil.emptyContainer();
+ }
+
+ @Override
+ protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider()
+ {
+ return new CollaborationsItemProvider()
+ {
+ @Override
+ public Font getFont(Object obj)
+ {
+ if (obj instanceof IBuddyCollaboration)
+ {
+ if (obj == getCollaborationsPane().getActiveCollaboration())
+ {
+ return getBold();
+ }
+ }
+
+ return super.getFont(obj);
+ }
+ };
+ }
+
+ protected void initFacilityPaneCreators()
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, OM.EXT_POINT);
+ for (final IConfigurationElement element : elements)
+ {
+ if ("facilityPaneCreator".equals(element.getName())) //$NON-NLS-1$
+ {
+ try
+ {
+ IFacilityPaneCreator creator = (IFacilityPaneCreator)element.createExecutableExtension("class"); //$NON-NLS-1$
+ facilityPaneCreators.put(creator.getType(), creator);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class StartFacilityAction extends SafeAction
+ {
+ private final String type;
+
+ private IBuddyCollaboration collaboration;
+
+ private StartFacilityAction(IBuddyCollaboration collaboration, String type, ImageDescriptor descriptor)
+ {
+ super(MessageFormat.format(Messages.getString("CollaborationsView_2"), StringUtil.cap(type)), AS_RADIO_BUTTON); //$NON-NLS-1$
+ setToolTipText(MessageFormat.format(Messages.getString("CollaborationsView_3"), type)); //$NON-NLS-1$
+ setImageDescriptor(descriptor);
+ this.collaboration = collaboration;
+ this.type = type;
+ }
+
+ @Override
+ protected void safeRun() throws Exception
+ {
+ collaboration.installFacility(type);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/FacilityPane.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/FacilityPane.java index 41f0ad2939..9e0ae522d5 100644 --- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/FacilityPane.java +++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/FacilityPane.java @@ -1,242 +1,242 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.buddies.internal.ui.views; - -import org.eclipse.net4j.buddies.common.IFacility; -import org.eclipse.net4j.buddies.internal.ui.bundle.OM; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.ui.UIUtil; - -import org.eclipse.jface.action.CoolBarManager; -import org.eclipse.jface.action.IContributionManager; -import org.eclipse.jface.action.ICoolBarManager; -import org.eclipse.jface.action.ToolBarManager; -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.Control; -import org.eclipse.swt.widgets.CoolBar; -import org.eclipse.swt.widgets.Layout; - -/** - * @author Eike Stepper - */ -public abstract class FacilityPane extends Composite implements IListener -{ - private IFacility facility; - - private CollaborationsPane collaborationsPane; - - private CoolBarManager coolBarManager; - - private Control control; - - public FacilityPane(CollaborationsPane collaborationsPane, int style) - { - super(collaborationsPane, style); - this.collaborationsPane = collaborationsPane; - setLayout(new FacilityPaneLayout()); - - ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.RIGHT | SWT.WRAP); - fillCoolBar(toolBarManager); - - coolBarManager = new CoolBarManager(SWT.FLAT | SWT.RIGHT | SWT.WRAP); - coolBarManager.add(toolBarManager); - coolBarManager.setLockLayout(true); - coolBarManager.createControl(this); - coolBarManager.update(true); - - Composite composite = new Composite(this, SWT.NONE); - composite.setLayout(UIUtil.createGridLayout(1)); - - control = createUI(composite); - control.setLayoutData(UIUtil.createGridData()); - } - - @Override - public void dispose() - { - facility.removeListener(this); - coolBarManager.dispose(); - super.dispose(); - } - - public IFacility getFacility() - { - return facility; - } - - public void setFacility(IFacility facility) - { - this.facility = facility; - facility.addListener(this); - } - - public CollaborationsPane getCollaborationsPane() - { - return collaborationsPane; - } - - public ICoolBarManager getCoolBarManager() - { - return coolBarManager; - } - - public Control getControl() - { - return control; - } - - public final void notifyEvent(final IEvent event) - { - try - { - control.getDisplay().syncExec(new Runnable() - { - public void run() - { - try - { - handleEvent(event); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - } - }); - } - catch (RuntimeException ignore) - { - } - } - - protected abstract void handleEvent(IEvent event) throws Exception; - - public void hidden(FacilityPane newPane) - { - } - - public void showed(FacilityPane oldPane) - { - } - - protected abstract Control createUI(Composite parent); - - protected CoolBar getCoolBarControl() - { - if (coolBarManager != null) - { - return coolBarManager.getControl(); - } - - return null; - } - - protected void fillCoolBar(IContributionManager manager) - { - } - - /** - * @author Eike Stepper - * @see org.eclipse.jface.window.ApplicationWindow.ApplicationWindowLayout - */ - public class FacilityPaneLayout extends Layout - { - static final int BAR_SIZE = 23; - - @Override - protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) - { - if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) - { - return new Point(wHint, hHint); - } - - Point result = new Point(0, 0); - Control[] ws = composite.getChildren(); - for (int i = 0; i < ws.length; i++) - { - Control w = ws[i]; - boolean hide = false; - if (w == getCoolBarControl()) - { - if (!coolBarChildrenExist()) - { - hide = true; - result.y += BAR_SIZE; - } - } - else if (i > 0) - { - hide = false; - } - - if (!hide) - { - Point e = w.computeSize(wHint, hHint, flushCache); - result.x = Math.max(result.x, e.x); - result.y += e.y; - } - } - - if (wHint != SWT.DEFAULT) - { - result.x = wHint; - } - - if (hHint != SWT.DEFAULT) - { - result.y = hHint; - } - - return result; - } - - @Override - protected void layout(Composite composite, boolean flushCache) - { - Rectangle clientArea = composite.getClientArea(); - Control[] ws = composite.getChildren(); - for (int i = 0; i < ws.length; i++) - { - Control w = ws[i]; - if (w == getCoolBarControl()) - { - if (coolBarChildrenExist()) - { - Point e = w.computeSize(clientArea.width, SWT.DEFAULT, flushCache); - w.setBounds(clientArea.x, clientArea.y, clientArea.width, e.y); - clientArea.y += e.y; - clientArea.height -= e.y; - } - } - else - { - w.setBounds(clientArea.x, clientArea.y, clientArea.width, clientArea.height); - } - } - } - - protected boolean coolBarChildrenExist() - { - CoolBar coolBarControl = getCoolBarControl(); - if (coolBarControl != null) - { - return coolBarControl.getItemCount() > 0; - } - - return false; - } - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.common.IFacility;
+import org.eclipse.net4j.buddies.internal.ui.bundle.OM;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.jface.action.CoolBarManager;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.ICoolBarManager;
+import org.eclipse.jface.action.ToolBarManager;
+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.Control;
+import org.eclipse.swt.widgets.CoolBar;
+import org.eclipse.swt.widgets.Layout;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class FacilityPane extends Composite implements IListener
+{
+ private IFacility facility;
+
+ private CollaborationsPane collaborationsPane;
+
+ private CoolBarManager coolBarManager;
+
+ private Control control;
+
+ public FacilityPane(CollaborationsPane collaborationsPane, int style)
+ {
+ super(collaborationsPane, style);
+ this.collaborationsPane = collaborationsPane;
+ setLayout(new FacilityPaneLayout());
+
+ ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.RIGHT | SWT.WRAP);
+ fillCoolBar(toolBarManager);
+
+ coolBarManager = new CoolBarManager(SWT.FLAT | SWT.RIGHT | SWT.WRAP);
+ coolBarManager.add(toolBarManager);
+ coolBarManager.setLockLayout(true);
+ coolBarManager.createControl(this);
+ coolBarManager.update(true);
+
+ Composite composite = new Composite(this, SWT.NONE);
+ composite.setLayout(UIUtil.createGridLayout(1));
+
+ control = createUI(composite);
+ control.setLayoutData(UIUtil.createGridData());
+ }
+
+ @Override
+ public void dispose()
+ {
+ facility.removeListener(this);
+ coolBarManager.dispose();
+ super.dispose();
+ }
+
+ public IFacility getFacility()
+ {
+ return facility;
+ }
+
+ public void setFacility(IFacility facility)
+ {
+ this.facility = facility;
+ facility.addListener(this);
+ }
+
+ public CollaborationsPane getCollaborationsPane()
+ {
+ return collaborationsPane;
+ }
+
+ public ICoolBarManager getCoolBarManager()
+ {
+ return coolBarManager;
+ }
+
+ public Control getControl()
+ {
+ return control;
+ }
+
+ public final void notifyEvent(final IEvent event)
+ {
+ try
+ {
+ control.getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ handleEvent(event);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ protected abstract void handleEvent(IEvent event) throws Exception;
+
+ public void hidden(FacilityPane newPane)
+ {
+ }
+
+ public void showed(FacilityPane oldPane)
+ {
+ }
+
+ protected abstract Control createUI(Composite parent);
+
+ protected CoolBar getCoolBarControl()
+ {
+ if (coolBarManager != null)
+ {
+ return coolBarManager.getControl();
+ }
+
+ return null;
+ }
+
+ protected void fillCoolBar(IContributionManager manager)
+ {
+ }
+
+ /**
+ * @author Eike Stepper
+ * @see org.eclipse.jface.window.ApplicationWindow.ApplicationWindowLayout
+ */
+ public class FacilityPaneLayout extends Layout
+ {
+ static final int BAR_SIZE = 23;
+
+ @Override
+ protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache)
+ {
+ if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT)
+ {
+ return new Point(wHint, hHint);
+ }
+
+ Point result = new Point(0, 0);
+ Control[] ws = composite.getChildren();
+ for (int i = 0; i < ws.length; i++)
+ {
+ Control w = ws[i];
+ boolean hide = false;
+ if (w == getCoolBarControl())
+ {
+ if (!coolBarChildrenExist())
+ {
+ hide = true;
+ result.y += BAR_SIZE;
+ }
+ }
+ else if (i > 0)
+ {
+ hide = false;
+ }
+
+ if (!hide)
+ {
+ Point e = w.computeSize(wHint, hHint, flushCache);
+ result.x = Math.max(result.x, e.x);
+ result.y += e.y;
+ }
+ }
+
+ if (wHint != SWT.DEFAULT)
+ {
+ result.x = wHint;
+ }
+
+ if (hHint != SWT.DEFAULT)
+ {
+ result.y = hHint;
+ }
+
+ return result;
+ }
+
+ @Override
+ protected void layout(Composite composite, boolean flushCache)
+ {
+ Rectangle clientArea = composite.getClientArea();
+ Control[] ws = composite.getChildren();
+ for (int i = 0; i < ws.length; i++)
+ {
+ Control w = ws[i];
+ if (w == getCoolBarControl())
+ {
+ if (coolBarChildrenExist())
+ {
+ Point e = w.computeSize(clientArea.width, SWT.DEFAULT, flushCache);
+ w.setBounds(clientArea.x, clientArea.y, clientArea.width, e.y);
+ clientArea.y += e.y;
+ clientArea.height -= e.y;
+ }
+ }
+ else
+ {
+ w.setBounds(clientArea.x, clientArea.y, clientArea.width, clientArea.height);
+ }
+ }
+ }
+
+ protected boolean coolBarChildrenExist()
+ {
+ CoolBar coolBarControl = getCoolBarControl();
+ if (coolBarControl != null)
+ {
+ return coolBarControl.getItemCount() > 0;
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/SessionManagerView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/SessionManagerView.java index c369d2eadb..9deb5a52f3 100644 --- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/SessionManagerView.java +++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/SessionManagerView.java @@ -1,153 +1,153 @@ -/* - * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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: - * Eike Stepper - initial API and implementation - */ -package org.eclipse.net4j.buddies.internal.ui.views; - -import org.eclipse.net4j.buddies.IBuddySession; -import org.eclipse.net4j.buddies.ISessionManager; -import org.eclipse.net4j.buddies.ISessionManagerEvent; -import org.eclipse.net4j.buddies.common.IBuddyStateEvent; -import org.eclipse.net4j.buddies.internal.ui.BuddiesItemProvider; -import org.eclipse.net4j.buddies.internal.ui.actions.ConnectAction; -import org.eclipse.net4j.buddies.internal.ui.actions.DisconnectAction; -import org.eclipse.net4j.buddies.internal.ui.actions.FlashAction; -import org.eclipse.net4j.buddies.internal.ui.actions.ReconnectAction; -import org.eclipse.net4j.buddies.internal.ui.actions.StateAction.DropDownAction; -import org.eclipse.net4j.util.container.IContainer; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; -import org.eclipse.net4j.util.ui.views.ContainerItemProvider; -import org.eclipse.net4j.util.ui.views.ContainerView; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -public abstract class SessionManagerView extends ContainerView implements IListener -{ - private IBuddySession session; - - private ConnectAction connectAction = new ConnectAction(); - - private DisconnectAction disconnectAction = new DisconnectAction(); - - private ReconnectAction reconnectAction = new ReconnectAction(); - - private FlashAction flashAction = new FlashAction(); - - private DropDownAction dropDownAction = new DropDownAction(); - - private Control control; - - public SessionManagerView() - { - } - - public IBuddySession getSession() - { - return session; - } - - @Override - public void dispose() - { - ISessionManager.INSTANCE.removeListener(this); - session = null; - super.dispose(); - } - - public void notifyEvent(IEvent event) - { - if (event instanceof ISessionManagerEvent) - { - queryBuddiesManager(); - } - else if (event instanceof IBuddyStateEvent) - { - if (session != null && event.getSource() == session.getSelf()) - { - updateState(); - } - } - } - - @Override - protected final Control createUI(Composite parent) - { - control = createControl(parent); - queryBuddiesManager(); - ISessionManager.INSTANCE.addListener(this); - return control; - } - - protected Control createControl(Composite parent) - { - return super.createUI(parent); - } - - @Override - protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider() - { - return new BuddiesItemProvider(); - } - - @Override - protected void fillLocalToolBar(IToolBarManager manager) - { - super.fillLocalToolBar(manager); - manager.add(dropDownAction); - } - - @Override - protected void fillLocalPullDown(IMenuManager manager) - { - manager.add(connectAction); - manager.add(disconnectAction); - manager.add(reconnectAction); - manager.add(new Separator()); - manager.add(flashAction); - super.fillLocalPullDown(manager); - } - - protected void queryBuddiesManager() - { - IBuddySession oldSession = session; - session = ISessionManager.INSTANCE.getSession(); - if (oldSession != session) - { - if (oldSession != null) - { - oldSession.removeListener(this); - oldSession.getSelf().removeListener(this); - } - - if (session != null) - { - session.addListener(this); - session.getSelf().addListener(this); - } - } - - resetInput(); - updateState(); - } - - protected void updateState() - { - connectAction.setEnabled(session == null); - disconnectAction.setEnabled(session != null); - reconnectAction.setEnabled(session != null); - flashAction.setEnabled(session != null && !ISessionManager.INSTANCE.isFlashing()); - dropDownAction.updateState(); - // control.setEnabled(session != null); - } -} +/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.ISessionManager;
+import org.eclipse.net4j.buddies.ISessionManagerEvent;
+import org.eclipse.net4j.buddies.common.IBuddyStateEvent;
+import org.eclipse.net4j.buddies.internal.ui.BuddiesItemProvider;
+import org.eclipse.net4j.buddies.internal.ui.actions.ConnectAction;
+import org.eclipse.net4j.buddies.internal.ui.actions.DisconnectAction;
+import org.eclipse.net4j.buddies.internal.ui.actions.FlashAction;
+import org.eclipse.net4j.buddies.internal.ui.actions.ReconnectAction;
+import org.eclipse.net4j.buddies.internal.ui.actions.StateAction.DropDownAction;
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
+import org.eclipse.net4j.util.ui.views.ContainerView;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public abstract class SessionManagerView extends ContainerView implements IListener
+{
+ private IBuddySession session;
+
+ private ConnectAction connectAction = new ConnectAction();
+
+ private DisconnectAction disconnectAction = new DisconnectAction();
+
+ private ReconnectAction reconnectAction = new ReconnectAction();
+
+ private FlashAction flashAction = new FlashAction();
+
+ private DropDownAction dropDownAction = new DropDownAction();
+
+ private Control control;
+
+ public SessionManagerView()
+ {
+ }
+
+ public IBuddySession getSession()
+ {
+ return session;
+ }
+
+ @Override
+ public void dispose()
+ {
+ ISessionManager.INSTANCE.removeListener(this);
+ session = null;
+ super.dispose();
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof ISessionManagerEvent)
+ {
+ queryBuddiesManager();
+ }
+ else if (event instanceof IBuddyStateEvent)
+ {
+ if (session != null && event.getSource() == session.getSelf())
+ {
+ updateState();
+ }
+ }
+ }
+
+ @Override
+ protected final Control createUI(Composite parent)
+ {
+ control = createControl(parent);
+ queryBuddiesManager();
+ ISessionManager.INSTANCE.addListener(this);
+ return control;
+ }
+
+ protected Control createControl(Composite parent)
+ {
+ return super.createUI(parent);
+ }
+
+ @Override
+ protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider()
+ {
+ return new BuddiesItemProvider();
+ }
+
+ @Override
+ protected void fillLocalToolBar(IToolBarManager manager)
+ {
+ super.fillLocalToolBar(manager);
+ manager.add(dropDownAction);
+ }
+
+ @Override
+ protected void fillLocalPullDown(IMenuManager manager)
+ {
+ manager.add(connectAction);
+ manager.add(disconnectAction);
+ manager.add(reconnectAction);
+ manager.add(new Separator());
+ manager.add(flashAction);
+ super.fillLocalPullDown(manager);
+ }
+
+ protected void queryBuddiesManager()
+ {
+ IBuddySession oldSession = session;
+ session = ISessionManager.INSTANCE.getSession();
+ if (oldSession != session)
+ {
+ if (oldSession != null)
+ {
+ oldSession.removeListener(this);
+ oldSession.getSelf().removeListener(this);
+ }
+
+ if (session != null)
+ {
+ session.addListener(this);
+ session.getSelf().addListener(this);
+ }
+ }
+
+ resetInput();
+ updateState();
+ }
+
+ protected void updateState()
+ {
+ connectAction.setEnabled(session == null);
+ disconnectAction.setEnabled(session != null);
+ reconnectAction.setEnabled(session != null);
+ flashAction.setEnabled(session != null && !ISessionManager.INSTANCE.isFlashing());
+ dropDownAction.updateState();
+ // control.setEnabled(session != null);
+ }
+}
|