📄 raplaclientserviceimpl.java
字号:
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Christopher Kohlhaas |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by the |
| Free Software Foundation. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.client.internal;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.rapla.client.ClientService;
import org.rapla.client.RaplaClientListener;
import org.rapla.components.calendar.DateRenderer;
import org.rapla.components.iolayer.DefaultIO;
import org.rapla.components.iolayer.IOInterface;
import org.rapla.components.iolayer.WebstartIO;
import org.rapla.components.util.Mutex;
import org.rapla.components.xmlbundle.I18nBundle;
import org.rapla.components.xmlbundle.LocaleSelector;
import org.rapla.entities.User;
import org.rapla.entities.configuration.CalendarModelConfiguration;
import org.rapla.entities.configuration.Preferences;
import org.rapla.entities.configuration.RaplaConfiguration;
import org.rapla.entities.dynamictype.DynamicType;
import org.rapla.entities.dynamictype.DynamicTypeAnnotations;
import org.rapla.facade.ClientFacade;
import org.rapla.facade.UpdateErrorListener;
import org.rapla.framework.PluginDescriptor;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaContextException;
import org.rapla.framework.RaplaException;
import org.rapla.framework.RaplaLocale;
import org.rapla.framework.StartupEnvironment;
import org.rapla.framework.internal.ContainerImpl;
import org.rapla.gui.CalendarModel;
import org.rapla.gui.EditController;
import org.rapla.gui.InfoFactory;
import org.rapla.gui.MenuExtensionPoint;
import org.rapla.gui.MenuFactory;
import org.rapla.gui.ReservationController;
import org.rapla.gui.TreeFactory;
import org.rapla.gui.internal.CalendarOption;
import org.rapla.gui.internal.ConnectionOption;
import org.rapla.gui.internal.LocaleOption;
import org.rapla.gui.internal.MainFrame;
import org.rapla.gui.internal.MenuFactoryImpl;
import org.rapla.gui.internal.RaplaDateRenderer;
import org.rapla.gui.internal.StoreCalendarSelectionAction;
import org.rapla.gui.internal.UserOption;
import org.rapla.gui.internal.common.CalendarModelImpl;
import org.rapla.gui.internal.common.CalendarSelectionModel;
import org.rapla.gui.internal.common.InternMenus;
import org.rapla.gui.internal.common.RaplaClipboard;
import org.rapla.gui.internal.edit.EditControllerImpl;
import org.rapla.gui.internal.edit.reservation.NoWizard;
import org.rapla.gui.internal.edit.reservation.ReservationControllerImpl;
import org.rapla.gui.internal.view.InfoFactoryImpl;
import org.rapla.gui.internal.view.LicenseInfoUI;
import org.rapla.gui.internal.view.TreeFactoryImpl;
import org.rapla.gui.toolkit.ErrorDialog;
import org.rapla.gui.toolkit.FrameControllerList;
import org.rapla.gui.toolkit.MenuInterface;
import org.rapla.gui.toolkit.RaplaFrame;
import org.rapla.gui.toolkit.RaplaMenu;
import org.rapla.gui.toolkit.RaplaMenubar;
import org.rapla.gui.toolkit.RaplaSeparator;
import org.rapla.gui.toolkit.RaplaWidget;
import org.rapla.plugin.RaplaExtensionPoints;
import org.rapla.plugin.weekview.WeekViewFactory;
/** Implemention of the ClientService.
*/
public class RaplaClientServiceImpl extends ContainerImpl implements ClientService,UpdateErrorListener
{
Vector listenerList = new Vector();
LoadingProgress progress;
I18nBundle i18n;
ClientFacade facade;
boolean started;
boolean restartingGUI;
String facadeName;
boolean defaultLanguageChoosen;
FrameControllerList frameControllerList;
public RaplaClientServiceImpl(RaplaContext parentContext, Configuration config) throws RaplaException {
super(parentContext, config);
}
class DefaultMenuInsertPoint implements MenuExtensionPoint {
MenuInterface menu;
String insertId;
public DefaultMenuInsertPoint( MenuInterface menu, String insertId) {
this.menu = menu;
this.insertId = insertId;
}
public void insert( JMenuItem item )
{
menu.insertAfterId( item, insertId );
}
public void insert( JSeparator seperator )
{
menu.insertAfterId( seperator,insertId );
}
}
protected void init() throws RaplaException {
defaultLanguageChoosen = true;
// !!Warning: Theres a trivial patent for the use of Progress Bars see http://swpat.ffii.org/patents/txt/ep/0394/160/
// You can uncomment the following two lines to disable the progressBar
progress = new LoadingProgress();
progress.start(1,5);
super.init( );
facadeName = m_config.getChild("facade").getValue("*");
frameControllerList = new FrameControllerList();
frameControllerList.enableLogging(getLogger().getChildLogger("framelist"));
addContainerProvidedComponentInstance(FrameControllerList.ROLE,frameControllerList);
addContainerProvidedComponent( "org.rapla.gui.WelcomeField", LicenseInfoUI.class.getName() );
addContainerProvidedComponent( MAIN_COMPONENT, RaplaFrame.class.getName());
RaplaMenubar menuBar = new RaplaMenubar();
RaplaMenu systemMenu = new RaplaMenu( InternMenus.FILE_MENU_ROLE );
RaplaMenu editMenu = new RaplaMenu( InternMenus.EDIT_MENU_ROLE );
RaplaMenu viewMenu = new RaplaMenu( InternMenus.VIEW_MENU_ROLE );
RaplaMenu helpMenu = new RaplaMenu( InternMenus.EXTRA_MENU_ROLE );
RaplaMenu newMenu = new RaplaMenu( InternMenus.NEW_MENU_ROLE );
RaplaMenu adminMenu = new RaplaMenu( InternMenus.ADMIN_MENU_ROLE );
RaplaMenu importMenu = new RaplaMenu( InternMenus.IMPORT_MENU_ROLE);
RaplaMenu exportMenu = new RaplaMenu( InternMenus.EXPORT_MENU_ROLE);
menuBar.add( systemMenu );
menuBar.add( editMenu );
menuBar.add( viewMenu );
menuBar.add( helpMenu );
addContainerProvidedComponentInstance( RaplaExtensionPoints.ADMIN_MENU_EXTENSION_POINT, new DefaultMenuInsertPoint( adminMenu, null));
addContainerProvidedComponentInstance( RaplaExtensionPoints.IMPORT_MENU_EXTENSION_POINT, new DefaultMenuInsertPoint( importMenu, null));
addContainerProvidedComponentInstance( RaplaExtensionPoints.EXPORT_MENU_EXTENSION_POINT, new DefaultMenuInsertPoint( exportMenu, null));
addContainerProvidedComponentInstance( RaplaExtensionPoints.HELP_MENU_EXTENSION_POINT, new DefaultMenuInsertPoint( helpMenu, null));
addContainerProvidedComponentInstance( RaplaExtensionPoints.VIEW_MENU_EXTENSION_POINT, new DefaultMenuInsertPoint( viewMenu, null));
addContainerProvidedComponentInstance( RaplaExtensionPoints.EDIT_MENU_EXTENSION_POINT, new DefaultMenuInsertPoint( editMenu, "EDIT_END"));
addContainerProvidedComponentInstance( InternMenus.MENU_BAR, menuBar);
addContainerProvidedComponentInstance( InternMenus.FILE_MENU_ROLE, systemMenu );
addContainerProvidedComponentInstance( InternMenus.EDIT_MENU_ROLE, editMenu);
addContainerProvidedComponentInstance( InternMenus.VIEW_MENU_ROLE, viewMenu);
addContainerProvidedComponentInstance( InternMenus.ADMIN_MENU_ROLE, adminMenu);
addContainerProvidedComponentInstance( InternMenus.IMPORT_MENU_ROLE, importMenu );
addContainerProvidedComponentInstance( InternMenus.EXPORT_MENU_ROLE, exportMenu );
addContainerProvidedComponentInstance( InternMenus.NEW_MENU_ROLE, newMenu );
addContainerProvidedComponentInstance( InternMenus.EXTRA_MENU_ROLE, helpMenu );
editMenu.add( new RaplaSeparator("EDIT_BEGIN"));
editMenu.add( new RaplaSeparator("EDIT_END"));
addContainerProvidedComponent( RaplaClipboard.ROLE, RaplaClipboard.class.getName() );
addContainerProvidedComponent( TreeFactory.ROLE, TreeFactoryImpl.class.getName() );
addContainerProvidedComponent( MenuFactory.ROLE, MenuFactoryImpl.class.getName() );
addContainerProvidedComponent( InfoFactory.ROLE, InfoFactoryImpl.class.getName() );
addContainerProvidedComponent( EditController.ROLE, EditControllerImpl.class.getName() );
addContainerProvidedComponent( ReservationController.ROLE, ReservationControllerImpl.class.getName() );
addContainerProvidedComponent( DateRenderer.class.getName(), RaplaDateRenderer.class.getName() );
addContainerProvidedComponent( RaplaExtensionPoints.RESERVATION_WIZARD_EXTENSION, NoWizard.class.getName() );
addContainerProvidedComponentInstance( SESSION_MAP, new HashMap());
addContainerProvidedComponent ( RaplaExtensionPoints.USER_OPTION_PANEL_EXTENSION, UserOption.class.getName() );
addContainerProvidedComponent ( RaplaExtensionPoints.USER_OPTION_PANEL_EXTENSION, CalendarOption.class.getName() );
addContainerProvidedComponent ( RaplaExtensionPoints.USER_OPTION_PANEL_EXTENSION, LocaleOption.class.getName() );
addContainerProvidedComponent ( RaplaExtensionPoints.SYSTEM_OPTION_PANEL_EXTENSION, CalendarOption.class.getName() );
boolean webstartEnabled =((StartupEnvironment)getContext().lookup(StartupEnvironment.ROLE)).getStartupMode() == StartupEnvironment.WEBSTART;
if (webstartEnabled) {
addContainerProvidedComponent( IOInterface.ROLE,WebstartIO.class.getName() );
} else {
addContainerProvidedComponent( IOInterface.ROLE,DefaultIO.class.getName() );
}
if ( progress != null)
{
progress.advance();
}
}
public ClientFacade getFacade() {
return facade;
}
public void start() throws Exception {
if (started)
return;
try {
if (progress != null)
progress.advance();
getLogger().debug("RaplaClient started");
i18n = (I18nBundle) getContext().lookup(I18nBundle.ROLE );
facade = (ClientFacade) getContext().lookup(ClientFacade.ROLE + "/" + facadeName);
facade.addUpdateErrorListener(this);
if (progress != null)
progress.advance();
if (!facade.isSessionActive()) {
startLogin();
} else {
beginRaplaSession();
}
} catch (Exception ex) {
throw ex;
} finally {
if (progress != null)
progress.close();
}
}
/**
* @throws RaplaException
*
*/
private void beginRaplaSession() throws RaplaException {
initLanguage();
CalendarModel model = createCalendarModel();
addContainerProvidedComponentInstance( CalendarModel.ROLE, model );
addContainerProvidedComponentInstance( CalendarSelectionModel.ROLE, model );
if ( getFacade().isClientForServer() )
{
addContainerProvidedComponent ( RaplaExtensionPoints.SYSTEM_OPTION_PANEL_EXTENSION, ConnectionOption.class.getName() );
}
List pluginList;
try {
pluginList = (List) getContext().lookup( PluginDescriptor.PLUGIN_LIST);
} catch (RaplaContextException ex) {
throw new RaplaException (ex );
}
initializePlugins( pluginList, getFacade().getPreferences( null) );
started = true;
javax.swing.ToolTipManager.sharedInstance().setDismissDelay( 10000 );
RaplaFrame mainComponent = (RaplaFrame) getContext().lookup( MAIN_COMPONENT );
mainComponent.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
if ( !isRestartingGUI()) {
stop();
} else {
restartingGUI = false;
}
} catch (Exception ex) {
getLogger().error(ex.getMessage(),ex);
}
}
});
MainFrame mainFrame = new MainFrame( getContext());
fireClientStarted();
mainFrame.show();
}
private void initLanguage() throws RaplaException, RaplaContextException
{
if ( !defaultLanguageChoosen)
{
Preferences prefs = (Preferences)facade.edit(facade.getPreferences());
RaplaLocale raplaLocale = (RaplaLocale) getContext().lookup(RaplaLocale.ROLE );
String currentLanguage = raplaLocale.getLocale().getLanguage();
prefs.putEntry( RaplaLocale.LANGUAGE_ENTRY, currentLanguage);
try
{
facade.store( prefs);
}
catch (Exception e)
{
getLogger().error("Can't store language change", e);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -