2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.rcp
;
18 import org
.argeo
.security
.ui
.rcp
.SecureWorkbenchWindowAdvisor
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.dnd
.DropTargetAdapter
;
21 import org
.eclipse
.swt
.dnd
.DropTargetEvent
;
22 import org
.eclipse
.swt
.graphics
.Image
;
23 import org
.eclipse
.swt
.widgets
.Event
;
24 import org
.eclipse
.swt
.widgets
.Listener
;
25 import org
.eclipse
.swt
.widgets
.Menu
;
26 import org
.eclipse
.swt
.widgets
.MenuItem
;
27 import org
.eclipse
.swt
.widgets
.Shell
;
28 import org
.eclipse
.swt
.widgets
.Tray
;
29 import org
.eclipse
.swt
.widgets
.TrayItem
;
30 import org
.eclipse
.ui
.IWorkbenchWindow
;
31 import org
.eclipse
.ui
.application
.IWorkbenchWindowConfigurer
;
32 import org
.eclipse
.ui
.part
.EditorInputTransfer
;
35 * Custom {@link SecureWorkbenchWindowAdvisor} which can add a tray. TODO: to
36 * be factorized in Argeo Commons and made more generic.
38 public class SlcSecureWorkbenchWindowAdvisor
extends
39 SecureWorkbenchWindowAdvisor
{
40 public final static String IN_TRAY_PROPERTY
= "org.argeo.slc.ui.inTray";
42 private TrayItem trayItem
;
44 public SlcSecureWorkbenchWindowAdvisor(
45 IWorkbenchWindowConfigurer configurer
, String username
) {
46 super(configurer
, username
);
49 public void postWindowOpen() {
50 String inTray
= System
.getProperty(IN_TRAY_PROPERTY
);
51 if (inTray
!= null && inTray
.equals("true")) {
57 public void preWindowOpen() {
58 getWindowConfigurer().addEditorAreaTransfer(
59 EditorInputTransfer
.getInstance());
60 getWindowConfigurer().configureEditorAreaDropListener(
61 new DropTargetAdapter() {
64 public void dragEnter(DropTargetEvent event
) {
65 System
.out
.println("DROP enter!!! " + event
);
69 public void dragLeave(DropTargetEvent event
) {
70 System
.out
.println("DROP leave!!! " + event
);
73 public void drop(DropTargetEvent event
) {
74 System
.out
.println("DROP drop!!! " + event
);
79 public void dropAccept(DropTargetEvent event
) {
80 System
.out
.println("DROP accept!!! " + event
);
81 super.dropAccept(event
);
85 super.preWindowOpen();
89 public boolean preWindowShellClose() {
90 // hide but do not dispose if tray is supported
91 if (trayItem
!= null) {
92 getWindowConfigurer().getWindow().getShell().setVisible(false);
98 /** Init tray support */
99 protected void initTray() {
100 IWorkbenchWindow window
= getWindowConfigurer().getWindow();
101 Shell shell
= window
.getShell();
102 final Tray tray
= shell
.getDisplay().getSystemTray();
103 trayItem
= new TrayItem(tray
, SWT
.NONE
);
104 if (trayItem
== null)
108 Image trayImage
= ClientRcpPlugin
.getDefault().getImageRegistry()
109 .get("argeoTrayIcon");
110 trayItem
.setImage(trayImage
);
111 trayItem
.setToolTipText("Argeo SLC");
114 // TODO: contribute more commands
115 trayItem
.addListener(SWT
.MenuDetect
, new Listener() {
116 public void handleEvent(Event event
) {
117 IWorkbenchWindow window
= getWindowConfigurer().getWindow();
118 Menu menu
= new Menu(window
.getShell(), SWT
.POP_UP
);
119 MenuItem exit
= new MenuItem(menu
, SWT
.NONE
);
120 exit
.setText("Exit");
121 exit
.addListener(SWT
.Selection
, new Listener() {
122 public void handleEvent(Event event
) {
123 getWindowConfigurer().getWorkbenchConfigurer()
124 .getWorkbench().close();
127 menu
.setVisible(true);
131 // add behavior when clicked upon
132 trayItem
.addListener(SWT
.Selection
, new Listener() {
133 public void handleEvent(Event event
) {
134 Shell shell
= getWindowConfigurer().getWindow().getShell();
135 if (shell
.isVisible()) {
136 if (shell
.getMinimized())
137 shell
.setMinimized(false);
139 shell
.setVisible(false);
140 shell
.setMinimized(true);
143 shell
.setVisible(true);
146 shell
.setMinimized(false);
152 // shell.setVisible(false);
156 public void dispose() {
157 if (trayItem
!= null)