Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryCommand.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 BERRYCOMMAND_H_
18 #define BERRYCOMMAND_H_
19 
21 
22 #include <berryICommandListener.h>
23 #include <berryIHandlerListener.h>
25 #include <berryIParameter.h>
26 
27 #include <berryParameterType.h>
28 
29 namespace berry
30 {
31 
32 class CommandCategory;
33 class ExecutionEvent;
34 struct IHandler;
35 
65 { // implements Comparable {
66 
67 public:
68 
70 
76 
81  static bool DEBUG_HANDLERS;
82 
88  static QString DEBUG_HANDLERS_COMMAND_ID;
89 
90 private:
91 
97 
101  IExecutionListenerWithChecks::Events executionEvents;
102  //ListenerList executionListeners;
103 
107  ICommandListener::Events commandEvents;
108 
114 
120  QString helpContextId;
121 
127  QList<SmartPointer<IParameter> > parameters;
128 
133  SmartPointer<ParameterType> returnType;
134 
135 protected:
136 
147  Command(const QString& id);
148 
149  friend class CommandManager;
150 
151 public:
152 
160  void AddCommandListener(ICommandListener* commandListener);
161 
169  void AddExecutionListener(IExecutionListener* executionListener);
170 
187  void AddState(const QString& id, const SmartPointer<State>& state) override;
188 
199  bool operator<(const Object* object) const override;
200 
229  void Define(const QString& name, const QString& description,
230  const SmartPointer<CommandCategory> category,
231  const QList<SmartPointer<IParameter> >& parameters = QList<SmartPointer<IParameter> >(),
232  const SmartPointer<ParameterType>& returnType = SmartPointer<ParameterType>(nullptr),
233  const QString& helpContextId = "");
234 
258  Object::Pointer ExecuteWithChecks(const SmartPointer<const ExecutionEvent> event);
259 
260 private:
261 
269  void FireCommandChanged(const SmartPointer<const CommandEvent> commandEvent);
270 
280  void FireNotDefined(const NotDefinedException* e);
281 
290  void FireNotEnabled(const NotEnabledException* e);
291 
300  void FireNotHandled(const NotHandledException* e);
301 
311  void FirePostExecuteFailure(const ExecutionException* e);
312 
320  void FirePostExecuteSuccess(const Object::Pointer returnValue);
321 
329  void FirePreExecute(const SmartPointer<const ExecutionEvent> event);
330 
331 public:
332 
343  SmartPointer<IHandler> GetHandler() const;
344 
353  QString GetHelpContextId() const;
354 
366  SmartPointer<IParameter> GetParameter(const QString& parameterId) const;
367 
377  QList<SmartPointer<IParameter> > GetParameters() const;
378 
393  SmartPointer<ParameterType> GetParameterType(const QString& parameterId) const;
394 
406  SmartPointer<ParameterType> GetReturnType() const;
407 
415  bool IsEnabled() const;
416 
425  void SetEnabled(const Object::Pointer& evaluationContext);
426 
434  bool IsHandled() const;
435 
443  void RemoveCommandListener(ICommandListener* commandListener);
444 
452  void RemoveExecutionListener(IExecutionListener* executionListener);
453 
465  void RemoveState(const QString& stateId) override;
466 
478  bool SetHandler(const SmartPointer<IHandler> handler);
479 
480 private:
481 
485  IHandlerListener* GetHandlerListener();
486 
491  void HandlerChanged(const SmartPointer<HandlerEvent>& handlerEvent) override;
492 
493 
494 public:
495 
502  QString ToString() const override;
503 
509  void Undefine() override;
510 };
511 
512 }
513 #endif /*BERRYCOMMAND_H_*/
static MsgHandler handler
Definition: usUtils.cpp:261
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
Implements transparent reference counting.
static bool DEBUG_HANDLERS
Definition: berryCommand.h:81
#define berryObjectMacro(...)
Definition: berryMacros.h:37
static bool DEBUG_COMMAND_EXECUTION
Definition: berryCommand.h:75
static QString DEBUG_HANDLERS_COMMAND_ID
Definition: berryCommand.h:88