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
;
34 /** Set here initial default size of the UI */
35 public class SlcSecureWorkbenchWindowAdvisor
extends
36 SecureWorkbenchWindowAdvisor
{
37 public final static String IN_TRAY_PROPERTY
= "org.argeo.slc.ui.inTray";
39 private TrayItem trayItem
;
41 public SlcSecureWorkbenchWindowAdvisor(
42 IWorkbenchWindowConfigurer configurer
, String username
) {
43 super(configurer
, username
);
46 public void postWindowOpen() {
47 String inTray
= System
.getProperty(IN_TRAY_PROPERTY
);
48 if (inTray
!= null && inTray
.equals("true")) {
54 public void preWindowOpen() {
55 getWindowConfigurer().addEditorAreaTransfer(
56 EditorInputTransfer
.getInstance());
57 getWindowConfigurer().configureEditorAreaDropListener(
58 new DropTargetAdapter() {
61 public void dragEnter(DropTargetEvent event
) {
62 System
.out
.println("DROP enter!!! " + event
);
66 public void dragLeave(DropTargetEvent event
) {
67 System
.out
.println("DROP leave!!! " + event
);
70 public void drop(DropTargetEvent event
) {
71 System
.out
.println("DROP drop!!! " + event
);
76 public void dropAccept(DropTargetEvent event
) {
77 System
.out
.println("DROP accept!!! " + event
);
78 super.dropAccept(event
);
82 super.preWindowOpen();
86 public boolean preWindowShellClose() {
87 // hide but do not dispose if tray is supported
88 if (trayItem
!= null) {
89 getWindowConfigurer().getWindow().getShell().setVisible(false);
95 /** Init tray support */
96 protected void initTray() {
97 IWorkbenchWindow window
= getWindowConfigurer().getWindow();
98 Shell shell
= window
.getShell();
99 final Tray tray
= shell
.getDisplay().getSystemTray();
100 trayItem
= new TrayItem(tray
, SWT
.NONE
);
101 if (trayItem
== null)
105 Image trayImage
= ClientRcpPlugin
.getDefault().getImageRegistry()
106 .get("argeoTrayIcon");
107 trayItem
.setImage(trayImage
);
108 trayItem
.setToolTipText("Argeo SLC");
111 // TODO: contribute more commands
112 trayItem
.addListener(SWT
.MenuDetect
, new Listener() {
113 public void handleEvent(Event event
) {
114 IWorkbenchWindow window
= getWindowConfigurer().getWindow();
115 Menu menu
= new Menu(window
.getShell(), SWT
.POP_UP
);
116 MenuItem exit
= new MenuItem(menu
, SWT
.NONE
);
117 exit
.setText("Exit");
118 exit
.addListener(SWT
.Selection
, new Listener() {
119 public void handleEvent(Event event
) {
120 getWindowConfigurer().getWorkbenchConfigurer()
121 .getWorkbench().close();
124 menu
.setVisible(true);
128 // add behavior when clicked upon
129 trayItem
.addListener(SWT
.Selection
, new Listener() {
130 public void handleEvent(Event event
) {
131 Shell shell
= getWindowConfigurer().getWindow().getShell();
132 if (shell
.isVisible()) {
133 if (shell
.getMinimized())
134 shell
.setMinimized(false);
136 shell
.setVisible(false);
137 shell
.setMinimized(true);
140 shell
.setVisible(true);
143 shell
.setMinimized(false);
149 // shell.setVisible(false);
153 public void dispose() {
154 if (trayItem
!= null)