Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryExecutionEvent.cpp
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 #include "berryExecutionEvent.h"
18 
21 #include "berryCommandCategory.h"
22 #include "berryState.h"
23 #include "berryIHandler.h"
24 
25 #include <berryObjectString.h>
26 
27 #include <QTextStream>
28 
29 namespace berry
30 {
31 
33 {
34 
35 }
36 
38  const ParameterMap& params, const Object::ConstPointer& trg,
39  const Object::Pointer& appContext)
40 : applicationContext(appContext), command(cmd), parameters(params), trigger(trg)
41 {
42 
43 }
44 
46 {
47  return applicationContext;
48 }
49 
51 {
52  return command;
53 }
54 
56  const QString& parameterId) const
57 {
58  if (command.IsNull())
59  {
60  throw ExecutionException(
61  "No command is associated with this execution event"); //$NON-NLS-1$
62  }
63 
64  try
65  {
66 // const ParameterType parameterType = command
67 // .getParameterType(parameterId);
68 // if (parameterType == null)
69 // {
70 // throw new ExecutionException(
71 // "Command does not have a parameter type for the given parameter"); //$NON-NLS-1$
72 // }
73 // const AbstractParameterValueConverter valueConverter = parameterType
74 // .getValueConverter();
75 // if (valueConverter == null)
76 // {
77 // throw new ExecutionException(
78 // "Command does not have a value converter"); //$NON-NLS-1$
79 // }
80  const QString stringValue = this->GetParameter(parameterId);
82 // const Object objectValue = valueConverter
83 // .convertToObject(stringValue);
84  return objectValue;
85  }
86  catch (NotDefinedException e)
87  {
88  throw ExecutionException("Command is not defined", e); //$NON-NLS-1$
89  }
90 // catch (ParameterValueConversionException e)
91 // {
92 // throw new ExecutionException(
93 // "The parameter string could not be converted to an object", e); //$NON-NLS-1$
94 // }
95 }
96 
97 QString ExecutionEvent::GetParameter(const QString& parameterId) const
98 {
99  ParameterMap::const_iterator res = parameters.find(parameterId);
100  if (res != parameters.end())
101  return res.value();
102  else return "";
103 }
104 
106 {
107  return parameters;
108 }
109 
111 {
112  return trigger;
113 }
114 
116 {
117  QString str;
118  QTextStream ss(&str);
119  ss << "ExecutionEvent(" << command->ToString() << ',' << parameters.size() << ','
120  << (trigger ? trigger->ToString() : QString()) << ',' << applicationContext->ToString() << ')';
121 
122  return str;
123 }
124 
125 }
berry::SmartPointer< const Self > ConstPointer
Definition: berryObject.h:89
object value (collection of name/value pairs).
Definition: jsoncpp.h:354
const Command::ConstPointer GetCommand() const
const Object::Pointer GetApplicationContext() const
QString GetParameter(const QString &parameterId) const
const Object::ConstPointer GetObjectParameterForExecution(const QString &parameterId) const
const Object::ConstPointer GetTrigger() const
UTF-8 string value.
Definition: jsoncpp.h:351
QString ToString() const override
const ParameterMap & GetParameters() const
QHash< QString, QString > ParameterMap