Medical Imaging Interaction Toolkit  2023.04.00
Medical Imaging Interaction Toolkit
berryCommandManager.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef BERRYCOMMANDMANAGER_H_
14 #define BERRYCOMMANDMANAGER_H_
15 
17 
19 #include "berryICommandListener.h"
23 
24 #include <QScopedPointer>
25 
26 
27 namespace berry
28 {
29 
30 struct IParameter;
31 struct IHandler;
32 class ParameterType;
33 class ParameterizedCommand;
34 class Parameterization;
35 class Command;
36 class CommandCategory;
37 
50 {
51 
52 private:
53 
54  typedef HandleObjectManager::HandleObjectsSet HandleObjectsSet;
55  typedef HandleObjectManager::HandleObjectsByIdMap HandleObjectsByIdMap;
56 
62  struct ExecutionListener: public IExecutionListenerWithChecks
63  {
64 
65  ExecutionListener(CommandManager* commandManager);
66 
67  void NotDefined(const QString& commandId,
68  const NotDefinedException* exception) override;
69 
70  void NotEnabled(const QString& commandId,
71  const NotEnabledException* exception) override;
72 
73  void NotHandled(const QString& commandId,
74  const NotHandledException* exception) override;
75 
76  void PostExecuteFailure(const QString& commandId,
77  const ExecutionException* exception) override;
78 
79  void PostExecuteSuccess(const QString& commandId,
80  const Object::Pointer& returnValue) override;
81 
82  void PreExecute(const QString& commandId, const SmartPointer<
83  const ExecutionEvent>& event) override;
84 
85  private:
86 
87  CommandManager* commandManager;
88  };
89 
90  struct CommandCategoryListener: public ICommandCategoryListener
91  {
92 
93  CommandCategoryListener(CommandManager* commandManager);
94 
95  void CategoryChanged(
96  const SmartPointer<const CommandCategoryEvent>& categoryEvent) override;
97 
98  private:
99 
100  CommandManager* commandManager;
101  };
102 
103  QScopedPointer<ICommandCategoryListener> categoryListener;
104 
105  struct CommandListener: public ICommandListener
106  {
107 
108  CommandListener(CommandManager* commandManager);
109 
110  void CommandChanged(const SmartPointer<const CommandEvent>& commandEvent) override;
111 
112  private:
113 
114  CommandManager* commandManager;
115 
116  };
117 
118  QScopedPointer<ICommandListener> commandListener;
119 
120  struct ParameterTypeListener: public IParameterTypeListener
121  {
122 
123  ParameterTypeListener(CommandManager* commandManager);
124 
125  void ParameterTypeChanged(
126  const SmartPointer<const ParameterTypeEvent>& parameterTypeEvent) override;
127 
128  private:
129 
130  CommandManager* commandManager;
131 
132  };
133 
134  QScopedPointer<IParameterTypeListener> parameterTypeListener;
135 
136 public:
137 
142  static const QString AUTOGENERATED_CATEGORY_ID; // = "org.blueberry.core.commands.categories.autogenerated";
143 
147  CommandManager();
148 
157  void AddCommandManagerListener(ICommandManagerListener* listener);
158 
167  void AddExecutionListener(IExecutionListener* listener);
168 
181  void DefineUncategorizedCategory(const QString& name,
182  const QString& description);
183 
223  SmartPointer<ParameterizedCommand> Deserialize(const QString& serializedParameterizedCommand);
224 
231  QList<SmartPointer<Command> > GetAllCommands() const;
232 
245  SmartPointer<CommandCategory> GetCategory(const QString& categoryId);
246 
258  SmartPointer<Command> GetCommand(const QString& commandId);
259 
266  QList<SmartPointer<CommandCategory> > GetDefinedCategories();
267 
274  QSet<QString> GetDefinedCategoryIds() const;
275 
282  QSet<QString> GetDefinedCommandIds() const;
283 
290  QList<SmartPointer<Command> > GetDefinedCommands() const;
291 
299  QSet<QString> GetDefinedParameterTypeIds() const;
300 
307  QList<SmartPointer<ParameterType> > GetDefinedParameterTypes();
308 
324  QString GetHelpContextId(const SmartPointer<const Command> command) const;
325 
337  SmartPointer<ParameterType> GetParameterType(const QString& parameterTypeId);
338 
345  void RemoveCommandManagerListener(ICommandManagerListener* listener);
346 
353  void RemoveExecutionListener(IExecutionListener* listener);
354 
368  void SetHandlersByCommandId(
369  const QHash<QString, SmartPointer<IHandler> >& handlersByCommandId);
370 
382  void SetHelpContextId(const SmartPointer<IHandler> handler,
383  const QString& helpContextId);
384 
399  void FireNotEnabled(const QString& commandId,
400  const NotEnabledException* exception);
401 
416  void FireNotDefined(const QString& commandId,
417  const NotDefinedException* exception);
418 
433  void FirePreExecute(const QString& commandId, const SmartPointer<
434  const ExecutionEvent> event);
435 
450  void FirePostExecuteSuccess(const QString& commandId,
451  Object::Pointer returnValue);
452 
467  void FirePostExecuteFailure(const QString& commandId,
468  const ExecutionException* exception);
469 
470 protected:
471 
476  static const char ESCAPE_CHAR; // = '%';
477 
481  static const char ID_VALUE_CHAR; // = '=';
482 
486  static const char PARAMETER_END_CHAR; // = ')';
487 
491  static const char PARAMETER_SEPARATOR_CHAR; // = ',';
492 
496  static const char PARAMETER_START_CHAR; // = '(';
497 
498  friend class ParameterizedCommand;
499 
500 private:
501 
522  static QString Unescape(const QString& escapedText);
523 
529  QHash<QString, SmartPointer<CommandCategory> > categoriesById;
530 
535  QSet<QString> definedCategoryIds;
536 
542  QSet<QString> definedParameterTypeIds;
543 
549  QScopedPointer<IExecutionListenerWithChecks> executionListener;
550 
555  IExecutionListenerWithChecks::Events executionEvents;
556 
560  ICommandManagerListener::Events commandManagerEvents;
561 
567  QHash<WeakPointer<IHandler>, QString> helpContextIdsByHandler;
568 
574  QHash<QString, SmartPointer<ParameterType> > parameterTypesById;
575 
584  void FireCommandManagerChanged(
586 
602  QList<Parameterization> GetParameterizations(
603  const QString& serializedParameters,
604  const QList<SmartPointer<IParameter> >& parameters) const;
605 
622  int UnescapedIndexOf(const QString& escapedText, const char ch) const;
623 
624 };
625 
626 }
627 
628 #endif /* BERRYCOMMANDMANAGER_H_ */
berry::HandleObjectManager::HandleObjectsSet
QSet< SmartPointer< HandleObject > > HandleObjectsSet
Definition: berryHandleObjectManager.h:42
berry::CommandManager
Definition: berryCommandManager.h:49
berryIExecutionListenerWithChecks.h
berry::IExecutionListener
Definition: berryIExecutionListener.h:35
berryHandleObjectManager.h
berryICommandListener.h
berry::CommandManager::PARAMETER_START_CHAR
static const char PARAMETER_START_CHAR
Definition: berryCommandManager.h:496
berry::SmartPointer< Self >
berryIParameterTypeListener.h
berry::CommandManager::ESCAPE_CHAR
static const char ESCAPE_CHAR
Definition: berryCommandManager.h:476
BERRY_COMMANDS
#define BERRY_COMMANDS
Definition: org_blueberry_core_commands_Export.h:26
berry::ICommandListener
Definition: berryICommandListener.h:37
berry::ParameterizedCommand
Definition: berryParameterizedCommand.h:40
berry::CommandManager::PARAMETER_END_CHAR
static const char PARAMETER_END_CHAR
Definition: berryCommandManager.h:486
berry::IParameterTypeListener
Definition: berryIParameterTypeListener.h:37
berry::CommandManager::PARAMETER_SEPARATOR_CHAR
static const char PARAMETER_SEPARATOR_CHAR
Definition: berryCommandManager.h:491
berry::ICommandCategoryListener
Definition: berryICommandCategoryListener.h:35
berry::CommandManager::AUTOGENERATED_CATEGORY_ID
static const QString AUTOGENERATED_CATEGORY_ID
Definition: berryCommandManager.h:142
berry::ICommandManagerListener
Definition: berryICommandManagerListener.h:37
berry::HandleObjectManager::HandleObjectsByIdMap
QHash< QString, SmartPointer< HandleObject > > HandleObjectsByIdMap
Definition: berryHandleObjectManager.h:43
berry::CommandManager::ID_VALUE_CHAR
static const char ID_VALUE_CHAR
Definition: berryCommandManager.h:481
berry::ICommandManagerListener::Events
Definition: berryICommandManagerListener.h:40
berry::IExecutionListenerWithChecks::Events
Definition: berryIExecutionListenerWithChecks.h:36
berry::HandleObjectManager
Definition: berryHandleObjectManager.h:37
berryICommandCategoryListener.h
berry::IExecutionListenerWithChecks
Definition: berryIExecutionListenerWithChecks.h:34
berryICommandManagerListener.h
berry
Definition: QmitkPropertyItemModel.h:24
berry::ExecutionEvent
Definition: berryExecutionEvent.h:37