⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 raplaclientserviceimpl.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }
        }
        else
        {
            String language = facade.getPreferences().getEntryAsString( RaplaLocale.LANGUAGE_ENTRY, null);
            if ( language != null)
            {
                LocaleSelector localeSelector = (LocaleSelector) getContext().lookup(LocaleSelector.ROLE);
                localeSelector.setLanguage( language );
            }
        }
    }

    protected void initializePlugins(List pluginList, Preferences preferences) throws RaplaException {
        RaplaConfiguration raplaConfig =(RaplaConfiguration)preferences.getEntry("org.rapla.plugin");
        // Add plugin configs
        for ( Iterator it = pluginList.iterator(); it.hasNext();  ) {
            PluginDescriptor pluginDescriptor = (PluginDescriptor)it.next();
            String pluginClassname = pluginDescriptor.getClass().getName();
            Configuration pluginConfig = null;
            if ( raplaConfig != null) {
                pluginConfig = raplaConfig.find("class", pluginClassname);
            }
            if ( pluginConfig == null) {
                pluginConfig = new DefaultConfiguration("plugin");
            }
            pluginDescriptor.provideServices( this, pluginConfig );
        }


        Collection clientPlugins = getAllServicesFor(RaplaExtensionPoints.CLIENT_EXTENSION);
        // start plugins
        for (Iterator it = clientPlugins.iterator();it.hasNext();) {
            String hint = (String) it.next();
            try {
                getContext().lookup( RaplaExtensionPoints.CLIENT_EXTENSION  + "/" + hint);
                getLogger().info( "Initialize " + hint );
            } catch (RaplaContextException ex ) {
                getLogger().error( "Can't initialize " + hint, ex );
            }
        }
    }

    public boolean isRestartingGUI() {
        return restartingGUI;
    }

    public void addRaplaClientListener(RaplaClientListener listener) {
        listenerList.add(listener);
    }

    public void removeRaplaClientListener(RaplaClientListener listener) {
        listenerList.remove(listener);
    }

    public RaplaClientListener[] getRaplaClientListeners() {
        return (RaplaClientListener[])listenerList.toArray(new RaplaClientListener[]{});
    }

    protected void fireClientClosed(boolean restart) {
        RaplaClientListener[] listeners = getRaplaClientListeners();
        for (int i=0;i<listeners.length;i++)
            listeners[i].clientClosed(restart);
    }

    protected void fireClientStarted() {
        RaplaClientListener[] listeners = getRaplaClientListeners();
        for (int i=0;i<listeners.length;i++)
            listeners[i].clientStarted();
    }
    
    protected void fireClientAborted() {
        RaplaClientListener[] listeners = getRaplaClientListeners();
        for (int i=0;i<listeners.length;i++)
            listeners[i].clientAborted();
    }

    public boolean isRunning() {
        return started;
    }

    public void restartGUI() {
        started = false;
        try {
            restartingGUI = true;
            frameControllerList.closeAll();
            removeAllComponents();
            init();
            start();
        } catch (Exception ex) {
            getLogger().error( ex.getMessage(), ex);
            stop();
        }
    }

    public void stop() {
        stop( false );
    }

    public void stop(boolean restart) {
        if (!started)
            return;

        try {
            facade.logout();
        } catch (RaplaException ex) {
            getLogger().error("Clean logout failed",ex);
        }
        getLogger().info("Bye");
        started = false;
        fireClientClosed(restart);
    }

    public void dispose() {
        if (frameControllerList != null)
            frameControllerList.closeAll();
        super.dispose();
        getLogger().debug("RaplaClient disposed");
    }


    private void startLogin()  throws Exception {
        Thread loginThread = new Thread() {
            public void run() {
                startLoginInThread();
            }
        };
        loginThread.setDaemon( false );
        loginThread.start();
    }

    /*
        selectionChanged();
    }

*/

    private void startLoginInThread()  {
        final Mutex loginMutex = new Mutex();
        try {
            RaplaWidget welcomeField = (RaplaWidget) getContext().lookup("org.rapla.gui.WelcomeField");
            final LanguageChooser languageChooser = new LanguageChooser( getLogger(), getContext());
            
            final LoginDialog dlg = LoginDialog.create(getContext(),welcomeField.getComponent()
                ,languageChooser.getComponent());
            
            Action languageChanged = new AbstractAction()
            {
                private static final long serialVersionUID = 1L;

                public void actionPerformed(ActionEvent evt) {
                    try {
                        String lang = languageChooser.getSelectedLanguage();
                        if (lang == null)
                        {
                            defaultLanguageChoosen = true;
                        }
                        else
                        {
                            defaultLanguageChoosen = false;
                            getLogger().debug("Language changing to " + lang );
                            LocaleSelector localeSelector = (LocaleSelector) getContext().lookup( LocaleSelector.ROLE );
                            localeSelector.setLanguage(lang);
                            getLogger().info("Language changed " + localeSelector.getLanguage() );
                        }
                    } catch (Exception ex) {
                        getLogger().error("Can't change language",ex);
                    }
                }
                
            };
            languageChooser.setChangeAction( languageChanged);
            
            //dlg.setIcon( i18n.getIcon("icon.rapla-small"));
            if (progress != null)
                progress.close();
            Action loginAction = new AbstractAction() {
                private static final long serialVersionUID = 1L;

                public void actionPerformed(ActionEvent evt) {
                    String username = dlg.getUsername();
                    char[] password = dlg.getPassword();
                    boolean success = false;
                    try {
                        success = login(username,password);
                        if ( !success )
                        {
                            showWarning(i18n.getString("error.login"), dlg);
                        }
                    } 
                    catch (RaplaException ex) 
                    {
                        showException(ex,dlg);
                    }
                    if ( success) {
                        dlg.close();
                        loginMutex.release();
                        try {
                            beginRaplaSession();
                        } catch (RaplaException ex) {
                            showException(ex, null);
                            stop();
                            fireClientAborted();
                        }
                    } // end of else
                }
                
            };
            Action exitAction = new AbstractAction() {
                private static final long serialVersionUID = 1L;
                public void actionPerformed(ActionEvent evt) {
                    dlg.close();
                    loginMutex.release();
                    stop();
                    fireClientAborted();
                }
            };
            loginAction.putValue(Action.NAME,i18n.getString("login"));
            exitAction.putValue(Action.NAME,i18n.getString("exit"));
            dlg.setIconImage(i18n.getIcon("icon.rapla_small").getImage());
            dlg.setLoginAction( loginAction);
            dlg.setExitAction( exitAction );
            dlg.setSize( 480, 270);
            FrameControllerList.centerWindowOnScreen( dlg) ;
            dlg.setVisible( true );
            loginMutex.aquire();
            loginMutex.aquire();
        } catch (Exception ex) {
            getLogger().error("Error during Login ", ex);
            stop();
            fireClientAborted();
        } finally {
            loginMutex.release();
        }
    }





    public void updateError(RaplaException ex) {
        getLogger().error("Error updating data", ex);
    }

    /**
     * @see org.rapla.facade.UpdateErrorListener#disconnected()
     */
    public void disconnected() {
        if ( started )
            stop( true );
    }


    public void restart()  {
        stop( true);
    }

    public void showException(Exception ex,Component component) {
        try {
            ErrorDialog dialog = new ErrorDialog(getContext());
            dialog.showExceptionDialog(ex,component);
        } catch (RaplaException ex2) {
            getLogger().error(ex2.getMessage(),ex2);
        }
    }

    private boolean login(String username, char[] password) throws RaplaException {
        if (facade.login(username,password)) {
            return true;
        } else {
            return false;
        }
    }

    public void showWarning(String warning,Component owner) {
        try {
            ErrorDialog dialog = new ErrorDialog(getContext());
            dialog.showWarningDialog(warning,owner);
        } catch (RaplaException ex2) {
            getLogger().error(ex2.getMessage(),ex2);
        }
    }


    private CalendarModel createCalendarModel() throws RaplaException {
        CalendarModelImpl model = new CalendarModelImpl( getContext());
        CalendarModelConfiguration conf = (CalendarModelConfiguration)getFacade().getPreferences().getEntry(StoreCalendarSelectionAction.CONFIG_ENTRY);
        if ( conf != null) {
            model.setConfiguration( conf );
        } else {
            DynamicType[] types = getFacade().getDynamicTypes( DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION);
            if ( types.length == 0 ) {
                types = getFacade().getDynamicTypes( DynamicTypeAnnotations.VALUE_PERSON_CLASSIFICATION);
            }
            model.setSelectedObjects( Collections.singletonList( types[0]) );
            model.setViewId( WeekViewFactory.WEEK_VIEW);
            User user = getFacade().getUser();
            if ( !user.isAdmin()) {
                model.selectUser( user );
            }
            model.setUser( user);
            /*
            model.setStartDate( null);
            model.setEndDate( null);*/
        }
        model.setSelectedDate( getFacade().today());
        return model;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -