📄 applicationworkbenchwindowadvisor.java
字号:
/*******************************************************************************
* Copyright (c) 2005 Jean-Michel Lemieux, Jeff McAffer 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
*
* Hyperbola is an RCP application developed for the book
* Eclipse Rich Client Platform -
* Designing, Coding, and Packaging Java Applications
* See http://eclipsercp.org
*
* Contributors:
* Jean-Michel Lemieux and Jeff McAffer - initial API and implementation
*******************************************************************************/
package org.eclipsercp.hyperbola;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
private Image statusImage;
private TrayItem trayItem;
private Image trayImage;
private ApplicationActionBarAdvisor actionBarAdvisor;
public ApplicationWorkbenchWindowAdvisor(
IWorkbenchWindowConfigurer configurer) {
super(configurer);
}
public ActionBarAdvisor createActionBarAdvisor(
IActionBarConfigurer configurer) {
actionBarAdvisor = new ApplicationActionBarAdvisor(configurer);
return actionBarAdvisor;
}
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(true);
configurer.setShowStatusLine(true);
configurer.setShowMenuBar(true);
}
public void dispose() {
if(statusImage != null)
statusImage.dispose();
if(trayImage != null)
trayImage.dispose();
if(trayItem != null)
trayItem.dispose();
}
public void postWindowOpen() {
initStatusLine();
final IWorkbenchWindow window = getWindowConfigurer().getWindow();
trayItem = initTaskItem(window);
if (trayItem != null) {
hookPopupMenu(window);
hookMinimize(window);
}
}
private void hookMinimize(final IWorkbenchWindow window) {
window.getShell().addShellListener(new ShellAdapter() {
public void shellIconified(ShellEvent e) {
window.getShell().setVisible(false);
}
});
trayItem.addListener(SWT.DefaultSelection, new Listener() {
public void handleEvent(Event event) {
Shell shell = window.getShell();
if (!shell.isVisible()) {
shell.setVisible(true);
window.getShell().setMinimized(false);
}
}
});
}
private void hookPopupMenu(final IWorkbenchWindow window) {
// Add listener for menu pop-up
trayItem.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event event) {
MenuManager trayMenu = new MenuManager();
Menu menu = trayMenu.createContextMenu(window.getShell());
actionBarAdvisor.fillTrayItem(trayMenu);
menu.setVisible(true);
}
});
}
private TrayItem initTaskItem(IWorkbenchWindow window) {
final Tray tray = window.getShell().getDisplay().getSystemTray();
if (tray == null)
return null;
trayItem = new TrayItem(tray, SWT.NONE);
trayImage = AbstractUIPlugin.imageDescriptorFromPlugin(
"org.eclipsercp.hyperbola", IImageKeys.ONLINE).createImage();
trayItem.setImage(trayImage);
trayItem.setToolTipText("Hyperbola");
return trayItem;
}
private void initStatusLine() {
statusImage = AbstractUIPlugin.imageDescriptorFromPlugin(
"org.eclipsercp.hyperbola", IImageKeys.ONLINE).createImage();
IStatusLineManager statusline = getWindowConfigurer()
.getActionBarConfigurer().getStatusLineManager();
statusline.setMessage(statusImage, "Online");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -