view_plugin.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: view_plugin.hpp,v $
- * PRODUCTION Revision 1000.5 2004/06/01 19:47:09 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.27
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_CORE___VIEWPLUGIN__HPP
- #define GUI_CORE___VIEWPLUGIN__HPP
- /* $Id: view_plugin.hpp,v 1000.5 2004/06/01 19:47:09 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software / database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software / database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- * CViewPlugin -- intermediate abstract class to bridge abstract
- * plugins and views.
- */
- #include <gui/utils/reporter.hpp>
- #include <gui/core/plugin.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/iview.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/view_exception.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/utils/message_box.hpp>
- #include <gui/plugin/PluginCommand.hpp>
- #include <gui/plugin/PluginReply.hpp>
- #include <gui/plugin/ViewCommand.hpp>
- BEGIN_NCBI_SCOPE
- template<typename ViewType>
- class CViewPlugin : public CPlugin<ViewType>
- {
- public:
- virtual void RunCommand(objects::CPluginMessage& msg);
- };
- template <typename ViewType>
- inline
- void CViewPlugin<ViewType>::RunCommand(objects::CPluginMessage& msg)
- {
- const objects::CPluginCommand& cmd = msg.GetRequest().GetCommand();
- objects::CPluginReply& reply = msg.SetReply();
- reply.SetStatus(objects::eMessageStatus_failed);
- switch ( cmd.GetCommand() ) {
- case objects::eViewCommand_new_view:
- try {
- // get the views meessage pool name stored in the
- // Plugin Message context field.
- string pool_name ;
- if (msg.CanGetContext()) {
- pool_name = msg.GetContext();
- }
- CRef<IView> view(new ViewType(msg, pool_name));
- if ( !view ) {
- return;
- }
-
- // retrieve the document for further processing
- IDocument* doc = view->GetDocument();
- if ( !doc ) {
- NCBI_THROW(CViewException, eInvalidView,
- "Failed to bind view to document");
- }
- // make sure our view receives (in order) the appropriate events
- view->OnDocumentChanged();
- doc->AttachView(view, pool_name);
- CDocManager::UpdateAllViews();
- view->Show();
-
- reply.SetStatus(objects::eMessageStatus_success);
- }
- catch (CException& e) {
- NcbiMessageBox(string("Error creating view:n") + e.GetMsg());
- }
- catch (std::exception& e) {
- NcbiMessageBox(string("Error creating view:n") + e.what());
- }
- #ifndef _DEBUG
- catch (...) {
- NcbiMessageBox("Unknown error creating view");
- }
- #endif
- break;
-
- default:
- break;
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- *
- * $Log: view_plugin.hpp,v $
- * Revision 1000.5 2004/06/01 19:47:09 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.27
- *
- * Revision 1.27 2004/04/26 17:34:09 ucko
- * Add headers needed by RunCommand's body, which G++ 3.4 always parses
- * immediately.
- *
- * Revision 1.26 2004/04/07 12:38:06 dicuccio
- * Pass CPluginMessage to derived view class constructor
- *
- * Revision 1.25 2004/01/06 20:46:36 dicuccio
- * Moved CFltkCursorGuard into CPlugin - broadly applied to all plugins
- *
- * Revision 1.24 2004/01/06 20:12:38 dicuccio
- * Use CFLtkCursorGuard to change to a waiting cursor
- *
- * Revision 1.23 2003/12/22 19:13:37 dicuccio
- * Call OnDocumentChanged() immediately after creation
- *
- * Revision 1.22 2003/12/09 15:52:46 dicuccio
- * Use CException::GetMsg() instead of what()
- *
- * Revision 1.21 2003/11/19 20:41:07 friedman
- * Added grouping views into group message pools
- *
- * Revision 1.20 2003/11/14 17:08:17 ucko
- * Add "std::" to exception in catch statement to resolve ambiguity
- * reported by Compaq's compiler.
- *
- * Revision 1.19 2003/11/06 19:59:12 dicuccio
- * Added #include for doc_manager.hpp
- *
- * Revision 1.18 2003/11/04 20:59:07 dicuccio
- * Use objects:: where required
- *
- * Revision 1.17 2003/11/04 17:09:04 dicuccio
- * Changed API to take a CPluginMessage instead of a paired command/reply
- *
- * Revision 1.16 2003/10/27 17:28:52 dicuccio
- * Removed unnecessary export specifier
- *
- * Revision 1.15 2003/10/16 15:48:07 dicuccio
- * Removed extraneous call to UpdateAllViews()
- *
- * Revision 1.14 2003/09/30 19:51:38 dicuccio
- * Cosmetic change to exception report
- *
- * Revision 1.13 2003/09/04 14:00:26 dicuccio
- * Introduce IDocument and IView as abstract base classes. Use IDocument instead
- * of CDocument.
- *
- * Revision 1.12 2003/08/05 16:53:59 dicuccio
- * Removed member CRef<> - leads to leak of view and document on exit, resolves
- * issue of genome workbench not shutting down politely
- *
- * Revision 1.11 2003/07/14 10:52:45 shomrat
- * Initial Revision
- *
- *
- * ===========================================================================
- */
- #endif // GUI_CORE___VIEWPLUGIN__HPP