Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
berryCommandManager.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef BERRYCOMMANDMANAGER_H_
18 #define BERRYCOMMANDMANAGER_H_
19 
21 
23 #include "berryICommandListener.h"
27 
28 #include <QScopedPointer>
29 
30 
31 namespace berry
32 {
33 
34 struct IParameter;
35 struct IHandler;
36 class ParameterType;
37 class ParameterizedCommand;
38 class Parameterization;
39 class Command;
40 class CommandCategory;
41 
54 {
55 
56 private:
57 
58  typedef HandleObjectManager::HandleObjectsSet HandleObjectsSet;
59  typedef HandleObjectManager::HandleObjectsByIdMap HandleObjectsByIdMap;
60 
66  struct ExecutionListener: public IExecutionListenerWithChecks
67  {
68 
69  ExecutionListener(CommandManager* commandManager);
70 
71  void NotDefined(const QString& commandId,
72  const NotDefinedException* exception) override;
73 
74  void NotEnabled(const QString& commandId,
75  const NotEnabledException* exception) override;
76 
77  void NotHandled(const QString& commandId,
78  const NotHandledException* exception) override;
79 
80  void PostExecuteFailure(const QString& commandId,
81  const ExecutionException* exception) override;
82 
83  void PostExecuteSuccess(const QString& commandId,
84  const Object::Pointer& returnValue) override;
85 
86  void PreExecute(const QString& commandId, const SmartPointer<
87  const ExecutionEvent>& event) override;
88 
89  private:
90 
91  CommandManager* commandManager;
92  };
93 
94  struct CommandCategoryListener: public ICommandCategoryListener
95  {
96 
97  CommandCategoryListener(CommandManager* commandManager);
98 
99  void CategoryChanged(
100  const SmartPointer<const CommandCategoryEvent>& categoryEvent) override;
101 
102  private:
103 
104  CommandManager* commandManager;
105  };
106 
107  QScopedPointer<ICommandCategoryListener> categoryListener;
108 
109  struct CommandListener: public ICommandListener
110  {
111 
112  CommandListener(CommandManager* commandManager);
113 
114  void CommandChanged(const SmartPointer<const CommandEvent>& commandEvent) override;
115 
116  private:
117 
118  CommandManager* commandManager;
119 
120  };
121 
122  QScopedPointer<ICommandListener> commandListener;
123 
124  struct ParameterTypeListener: public IParameterTypeListener
125  {
126 
127  ParameterTypeListener(CommandManager* commandManager);
128 
129  void ParameterTypeChanged(
130  const SmartPointer<const ParameterTypeEvent>& parameterTypeEvent) override;
131 
132  private:
133 
134  CommandManager* commandManager;
135 
136  };
137 
138  QScopedPointer<IParameterTypeListener> parameterTypeListener;
139 
140 public:
141 
146  static const QString AUTOGENERATED_CATEGORY_ID; // = "org.blueberry.core.commands.categories.autogenerated";
147 
151  CommandManager();
152 
161  void AddCommandManagerListener(ICommandManagerListener* listener);
162 
171  void AddExecutionListener(IExecutionListener* listener);
172 
185  void DefineUncategorizedCategory(const QString& name,
186  const QString& description);
187 
227  SmartPointer<ParameterizedCommand> Deserialize(const QString& serializedParameterizedCommand);
228 
235  QList<SmartPointer<Command> > GetAllCommands() const;
236 
249  SmartPointer<CommandCategory> GetCategory(const QString& categoryId);
250 
262  SmartPointer<Command> GetCommand(const QString& commandId);
263 
270  QList<SmartPointer<CommandCategory> > GetDefinedCategories();
271 
278  QSet<QString> GetDefinedCategoryIds() const;
279 
286  QSet<QString> GetDefinedCommandIds() const;
287 
294  QList<SmartPointer<Command> > GetDefinedCommands() const;
295 
303  QSet<QString> GetDefinedParameterTypeIds() const;
304 
311  QList<SmartPointer<ParameterType> > GetDefinedParameterTypes();
312 
328  QString GetHelpContextId(const SmartPointer<const Command> command) const;
329 
341  SmartPointer<ParameterType> GetParameterType(const QString& parameterTypeId);
342 
349  void RemoveCommandManagerListener(ICommandManagerListener* listener);
350 
357  void RemoveExecutionListener(IExecutionListener* listener);
358 
372  void SetHandlersByCommandId(
373  const QHash<QString, SmartPointer<IHandler> >& handlersByCommandId);
374 
386  void SetHelpContextId(const SmartPointer<IHandler> handler,
387  const QString& helpContextId);
388 
403  void FireNotEnabled(const QString& commandId,
404  const NotEnabledException* exception);
405 
420  void FireNotDefined(const QString& commandId,
421  const NotDefinedException* exception);
422 
437  void FirePreExecute(const QString& commandId, const SmartPointer<
438  const ExecutionEvent> event);
439 
454  void FirePostExecuteSuccess(const QString& commandId,
455  Object::Pointer returnValue);
456 
471  void FirePostExecuteFailure(const QString& commandId,
472  const ExecutionException* exception);
473 
474 protected:
475 
480  static const char ESCAPE_CHAR; // = '%';
481 
485  static const char ID_VALUE_CHAR; // = '=';
486 
490  static const char PARAMETER_END_CHAR; // = ')';
491 
495  static const char PARAMETER_SEPARATOR_CHAR; // = ',';
496 
500  static const char PARAMETER_START_CHAR; // = '(';
501 
502  friend class ParameterizedCommand;
503 
504 private:
505 
526  static QString Unescape(const QString& escapedText);
527 
533  QHash<QString, SmartPointer<CommandCategory> > categoriesById;
534 
539  QSet<QString> definedCategoryIds;
540 
546  QSet<QString> definedParameterTypeIds;
547 
553  QScopedPointer<IExecutionListenerWithChecks> executionListener;
554 
559  IExecutionListenerWithChecks::Events executionEvents;
560 
564  ICommandManagerListener::Events commandManagerEvents;
565 
571  QHash<WeakPointer<IHandler>, QString> helpContextIdsByHandler;
572 
578  QHash<QString, SmartPointer<ParameterType> > parameterTypesById;
579 
588  void FireCommandManagerChanged(
590 
606  QList<Parameterization> GetParameterizations(
607  const QString& serializedParameters,
608  const QList<SmartPointer<IParameter> >& parameters) const;
609 
626  int UnescapedIndexOf(const QString& escapedText, const char ch) const;
627 
628 };
629 
630 }
631 
632 #endif /* BERRYCOMMANDMANAGER_H_ */
static MsgHandler handler
Definition: usUtils.cpp:261
static const char PARAMETER_START_CHAR
QSet< SmartPointer< HandleObject > > HandleObjectsSet
static const char ESCAPE_CHAR
static const char PARAMETER_END_CHAR
static const char PARAMETER_SEPARATOR_CHAR
static const QString AUTOGENERATED_CATEGORY_ID
static const char ID_VALUE_CHAR
QHash< QString, SmartPointer< HandleObject > > HandleObjectsByIdMap