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