Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
af3
kernel
Commits
0aad52e6
Commit
0aad52e6
authored
8 years ago
by
Vincent Aravantinos
Browse files
Options
Downloads
Patches
Plain Diff
fixes + improves naming conventions
refs 2701
parent
ae2465e7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java
+86
-99
86 additions, 99 deletions
...tiss/tooling/kernel/ui/internal/views/ConstraintMenu.java
with
86 additions
and
99 deletions
org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java
+
86
−
99
View file @
0aad52e6
...
...
@@ -8,7 +8,6 @@
+-----------------------------------------------------------------------*/
package
org.fortiss.tooling.kernel.ui.internal.views
;
import
static
org
.
eclipse
.
jface
.
dialogs
.
MessageDialog
.
openError
;
import
static
org
.
eclipse
.
jface
.
resource
.
ImageDescriptor
.
createFromImage
;
import
java.util.Collections
;
...
...
@@ -21,13 +20,10 @@ import org.eclipse.jface.action.ActionContributionItem;
import
org.eclipse.jface.action.IAction
;
import
org.eclipse.jface.action.IContributionItem
;
import
org.eclipse.jface.action.MenuManager
;
import
org.eclipse.jface.dialogs.MessageDialog
;
import
org.eclipse.jface.resource.ImageDescriptor
;
import
org.eclipse.jface.viewers.DecorationOverlayIcon
;
import
org.eclipse.jface.viewers.IDecoration
;
import
org.eclipse.swt.graphics.Image
;
import
org.eclipse.swt.widgets.Display
;
import
org.eclipse.swt.widgets.Shell
;
import
org.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum
;
import
org.fortiss.tooling.kernel.model.constraints.ConstraintInstance
;
import
org.fortiss.tooling.kernel.model.constraints.ErrorConstraintInstanceStatus
;
...
...
@@ -55,7 +51,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash:
1B21D22C8C6B64442A8C6719C03D8D4E
* @ConQAT.Rating YELLOW Hash:
08124620B9BD785A307D615579E646E2
*/
public
class
ConstraintMenu
implements
IContextMenuContributor
{
...
...
@@ -67,50 +63,53 @@ public class ConstraintMenu implements IContextMenuContributor {
return
Collections
.
emptyList
();
}
return
((
IConstrained
)
selectedObject
).
getConstraintInstances
().
stream
()
.
filter
(
c
->
shouldGetMenuEntry
(
c
))
.
map
(
c
->
constraintToAction
(
c
,
(
IConstrained
)
selectedObject
))
.
filter
(
c
i
->
shouldGetMenuEntry
(
c
i
))
.
map
(
c
i
->
constraintToAction
(
c
i
,
(
IConstrained
)
selectedObject
))
.
collect
(
Collectors
.
toList
());
}
/**
* @param c
* @return <code>true</code> iff <code>c</code> should get a menu entry, i.e., if not successful
* and activated.
* <code>true</code> iff <code>ci</code> should get a menu entry, i.e., if not successful and
* activated.
*/
private
boolean
shouldGetMenuEntry
(
ConstraintInstance
c
)
{
IConstraintInstanceStatus
status
=
IConstraintUIService
.
getInstance
().
getStatus
(
c
);
private
boolean
shouldGetMenuEntry
(
ConstraintInstance
c
i
)
{
IConstraintInstanceStatus
status
=
IConstraintUIService
.
getInstance
().
getStatus
(
c
i
);
return
!(
status
==
null
||
status
instanceof
SuccessConstraintInstanceStatus
);
}
/**
* @param c
* @param elt
* @return The submenu or menu entry corresponding to the status of <code>c</code>.
* <code>elt</code> is needed to prevent displaying an entry to go to <code>elt</code>
* (not hurtful, but useless, since the user is already seeing it).
* Returns the submenu or menu entry corresponding to the status of <code>ci</code>.
* <code>elt</code> is needed to prevent displaying an entry to go to <code>elt</code> (not
* hurtful, but useless, since the user is already seeing it).
*/
private
IContributionItem
constraintToAction
(
ConstraintInstance
c
,
IConstrained
elt
)
{
IConstraintInstanceStatus
status
=
IConstraintUIService
.
getInstance
().
getStatus
(
c
);
private
IContributionItem
constraintToAction
(
ConstraintInstance
c
i
,
IConstrained
elt
)
{
IConstraintInstanceStatus
status
=
IConstraintUIService
.
getInstance
().
getStatus
(
c
i
);
ConstraintSubMenuBase
m
;
if
(
status
instanceof
FailedConstraintInstanceStatus
)
{
m
=
new
Check
FailingConstraintAction
(
c
,
elt
);
m
=
new
KnowMoreAbout
FailingConstraintAction
(
c
i
,
elt
);
}
else
if
(
status
instanceof
ErrorConstraintInstanceStatus
)
{
m
=
new
CheckErrorConstraintAction
(
c
,
elt
);
m
=
new
CheckErrorConstraintAction
(
c
i
,
elt
);
}
else
if
(
status
instanceof
OutdatedConstraintInstanceStatus
)
{
m
=
new
CheckOutdatedConstraintAction
(
c
,
elt
);
m
=
new
CheckOutdatedConstraintAction
(
c
i
,
elt
);
}
else
{
// should not happen
return
null
;
}
if
(
m
.
getItems
().
length
>
1
)
{
return
m
;
if
(
m
.
getItems
().
length
==
0
)
{
Action
a
=
new
Action
(
m
.
getMenuText
(),
m
.
getImageDescriptor
())
{
// nothing to do
};
return
new
ActionContributionItem
(
a
);
}
IAction
uniqueAction
=
m
.
getTopActionContribution
().
getAction
();
String
txt
=
m
.
getMenuText
();
String
newText
=
txt
+
" -> "
+
uniqueAction
.
getText
();
uniqueAction
.
setText
(
newText
);
uniqueAction
.
setImageDescriptor
(
m
.
getImageDescriptor
());
return
m
.
getTopActionContribution
();
if
(
m
.
getItems
().
length
==
1
)
{
IAction
uniqueAction
=
m
.
getTopActionContribution
().
getAction
();
String
txt
=
m
.
getMenuText
();
String
newText
=
txt
+
" -> "
+
uniqueAction
.
getText
();
uniqueAction
.
setText
(
newText
);
uniqueAction
.
setImageDescriptor
(
m
.
getImageDescriptor
());
return
m
.
getTopActionContribution
();
}
return
m
;
}
/** {@inheritDoc} */
...
...
@@ -123,21 +122,22 @@ public class ConstraintMenu implements IContextMenuContributor {
private
static
class
GoToConstrained
extends
Action
{
/** The constrained element to open. */
private
IConstrained
c
;
private
IConstrained
c
strd
;
/** Constructor. */
public
GoToConstrained
(
IConstrained
c
)
{
super
(
"Go to "
+
IModelElementHandlerService
.
getInstance
().
getName
(
c
),
createFromImage
(
IModelElementHandlerService
.
getInstance
().
getIcon
(
c
)));
this
.
c
=
c
;
public
GoToConstrained
(
IConstrained
c
strd
)
{
super
(
"Go to "
+
IModelElementHandlerService
.
getInstance
().
getName
(
c
strd
),
createFromImage
(
IModelElementHandlerService
.
getInstance
().
getIcon
(
c
strd
)));
this
.
c
strd
=
cstrd
;
}
/** {@inheritDoc} */
@Override
public
void
run
()
{
IModelElementHandler
<
EObject
>
handler
=
IModelElementHandlerService
.
getInstance
().
getModelElementHandler
(
c
);
EObject
eltToOpen
=
handler
==
null
?
c
:
handler
.
handleOpenModelElementRequest
(
c
);
IModelElementHandlerService
.
getInstance
().
getModelElementHandler
(
cstrd
);
EObject
eltToOpen
=
handler
==
null
?
cstrd
:
handler
.
handleOpenModelElementRequest
(
cstrd
);
IModelEditorBindingService
.
getInstance
().
openInEditor
(
eltToOpen
);
}
}
...
...
@@ -152,18 +152,29 @@ public class ConstraintMenu implements IContextMenuContributor {
ImageDescriptor
imgd
=
IConstraintUIService
.
getInstance
().
getIconImageDescriptor
(
ci
);
Image
img
=
imgd
==
null
?
null
:
imgd
.
createImage
();
if
(
img
==
null
)
{
return
null
;
if
(
IConstraintUIService
.
getInstance
().
shallDisplayAsWarning
(
ci
))
{
return
ESharedImages
.
WARNING
.
getImageDescriptor
();
}
return
ESharedImages
.
ERROR
.
getImageDescriptor
();
}
ImageDescriptor
[]
descriptors
=
new
ImageDescriptor
[
5
];
descriptors
[
IDecoration
.
BOTTOM_LEFT
]
=
overlay
;
return
new
DecorationOverlayIcon
(
img
,
descriptors
);
}
/** Action for creating a new prototype. */
/** Get the correct overlay for the given constraint. */
private
static
ImageDescriptor
getOverlay
(
ConstraintInstance
ci
)
{
if
(
IConstraintUIService
.
getInstance
().
shallDisplayAsWarning
(
ci
))
{
return
ESharedImages
.
WARNING_OVERLAY
.
getImageDescriptor
();
}
return
ESharedImages
.
ERROR_OVERLAY
.
getImageDescriptor
();
}
/** Base for action involved in a constraint submenu. */
private
static
class
ConstraintSubMenuBase
extends
MenuManager
{
/** The constraint. */
protected
ConstraintInstance
c
;
protected
ConstraintInstance
c
i
;
/**
* The action to get more information about the constraint status.
...
...
@@ -174,13 +185,15 @@ public class ConstraintMenu implements IContextMenuContributor {
protected
ActionContributionItem
moreInfoAction
;
/** Constructor. */
public
ConstraintSubMenuBase
(
ConstraintInstance
c
,
IConstrained
selectedElt
,
String
suffix
,
ImageDescriptor
overlay
)
{
super
(
getText
(
c
,
suffix
),
getIcon
(
c
,
overlay
),
null
);
this
.
c
=
c
;
moreInfoAction
=
new
ActionContributionItem
(
new
OpenStatusAction
());
this
.
add
(
moreInfoAction
);
for
(
ConstrainedWithChecksum
cwc
:
c
.
getConstrainedsWithChecksum
())
{
public
ConstraintSubMenuBase
(
ConstraintInstance
ci
,
IConstrained
selectedElt
,
String
suffix
,
ImageDescriptor
overlay
)
{
super
(
getText
(
ci
,
suffix
),
getIcon
(
ci
,
overlay
),
null
);
this
.
ci
=
ci
;
if
(
IConstraintUIService
.
getInstance
().
canOpen
(
ci
))
{
moreInfoAction
=
new
ActionContributionItem
(
new
OpenStatusAction
());
this
.
add
(
moreInfoAction
);
}
for
(
ConstrainedWithChecksum
cwc
:
ci
.
getConstrainedsWithChecksum
())
{
if
(!
selectedElt
.
equals
(
cwc
.
getConstrained
()))
{
this
.
add
(
new
ActionContributionItem
(
new
GoToConstrained
(
cwc
.
getConstrained
())));
}
...
...
@@ -195,7 +208,7 @@ public class ConstraintMenu implements IContextMenuContributor {
return
moreInfoAction
;
}
/** Action to update a constraint. */
/** Action to update a constraint.
Assumes the status *can be open*.
*/
protected
class
OpenStatusAction
extends
Action
{
/** Constructor. */
...
...
@@ -207,36 +220,16 @@ public class ConstraintMenu implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public
void
run
()
{
IConstraintInstanceStatus
status
=
IConstraintUIService
.
getInstance
().
getStatus
(
c
);
if
(
status
instanceof
OutdatedConstraintInstanceStatus
&&
IConstraintUIService
.
getInstance
().
canOpen
(
c
))
{
ICommandStackService
.
getInstance
().
runAsCommand
(
c
,
new
Runnable
()
{
IConstraintInstanceStatus
status
=
IConstraintUIService
.
getInstance
().
getStatus
(
ci
);
if
(
status
instanceof
OutdatedConstraintInstanceStatus
)
{
ICommandStackService
.
getInstance
().
runAsCommand
(
ci
,
new
Runnable
()
{
@Override
public
void
run
()
{
IConstraintUIService
.
getInstance
().
openStatus
(
c
);
IConstraintUIService
.
getInstance
().
openStatus
(
c
i
);
}
});
return
;
}
if
(
IConstraintUIService
.
getInstance
().
canOpen
(
c
))
{
IConstraintUIService
.
getInstance
().
openStatus
(
c
);
}
else
{
// In the very rare cases where the status cannot be open (if the defaults are
// used, this should not happen), we provide some defaults.
Shell
sh
=
Display
.
getCurrent
().
getActiveShell
();
String
name
=
ConstraintMenu
.
getText
(
c
,
""
);
if
(
status
instanceof
FailedConstraintInstanceStatus
)
{
String
msg
=
(
name
==
null
?
"The "
:
name
);
msg
+=
" is not satisfied."
;
MessageDialog
.
openInformation
(
sh
,
"Unsatisfied constraint"
,
msg
);
}
else
if
(
status
instanceof
ErrorConstraintInstanceStatus
)
{
String
msg
=
"There was an error while verifying "
;
msg
+=
(
name
==
null
?
"the "
:
""
)
+
name
+
"."
;
openError
(
sh
,
"Error while verifying constraint"
,
msg
);
}
else
if
(
status
instanceof
OutdatedConstraintInstanceStatus
)
{
String
msg
=
(
name
==
null
?
"The "
:
name
)
+
" is outdated."
;
MessageDialog
.
openWarning
(
sh
,
"Outdated constraint"
,
msg
);
}
IConstraintUIService
.
getInstance
().
openStatus
(
ci
);
}
}
}
...
...
@@ -246,22 +239,22 @@ public class ConstraintMenu implements IContextMenuContributor {
private
static
class
CheckOutdatedConstraintAction
extends
ConstraintSubMenuBase
{
/** Constructor. */
public
CheckOutdatedConstraintAction
(
ConstraintInstance
c
,
IConstrained
selectedElt
)
{
super
(
c
,
selectedElt
,
"Outdated"
,
ESharedImages
.
WARNING_OVERLAY
.
getImageDescriptor
());
public
CheckOutdatedConstraintAction
(
ConstraintInstance
c
i
,
IConstrained
selectedElt
)
{
super
(
c
i
,
selectedElt
,
"Outdated"
,
ESharedImages
.
WARNING_OVERLAY
.
getImageDescriptor
());
IAction
action
=
moreInfoAction
.
getAction
();
action
.
setImageDescriptor
(
ToolingKernelUIActivator
.
getImageDescriptor
(
"icons/ok.png"
));
action
.
setText
(
"Check"
);
}
}
/** Action for
creating a new prototype
. */
private
static
class
Check
UnsuccessfulConstraintAction
extends
ConstraintSubMenuBase
{
/** Action for
knowing more about some unsuccessful constraint
. */
private
static
class
KnowMoreAbout
UnsuccessfulConstraintAction
extends
ConstraintSubMenuBase
{
/** Constructor. */
public
Check
UnsuccessfulConstraintAction
(
ConstraintInstance
c
,
IConstrained
selectedElt
,
String
suffix
)
{
super
(
c
,
selectedElt
,
suffix
,
getOverlay
(
c
));
List
<
IFix
>
fixes
=
IConstraintService
.
getInstance
().
fixes
(
c
);
public
KnowMoreAbout
UnsuccessfulConstraintAction
(
ConstraintInstance
c
i
,
IConstrained
selectedElt
,
String
suffix
)
{
super
(
c
i
,
selectedElt
,
suffix
,
getOverlay
(
c
i
));
List
<
IFix
>
fixes
=
IConstraintService
.
getInstance
().
fixes
(
c
i
);
if
(
fixes
!=
null
)
{
for
(
IFix
fix
:
fixes
)
{
this
.
add
(
new
ActionContributionItem
(
new
FixAction
(
fix
)));
...
...
@@ -269,14 +262,6 @@ public class ConstraintMenu implements IContextMenuContributor {
}
}
/** Get the correct overlay for the given constraint. */
private
static
ImageDescriptor
getOverlay
(
ConstraintInstance
c
)
{
if
(
IConstraintUIService
.
getInstance
().
shallDisplayAsWarning
(
c
))
{
return
ESharedImages
.
WARNING_OVERLAY
.
getImageDescriptor
();
}
return
ESharedImages
.
ERROR_OVERLAY
.
getImageDescriptor
();
}
/** Action to update a constraint. */
private
class
FixAction
extends
Action
{
...
...
@@ -293,32 +278,34 @@ public class ConstraintMenu implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public
void
run
()
{
ICommandStackService
.
getInstance
().
runAsCommand
(
c
,
new
Runnable
()
{
ICommandStackService
.
getInstance
().
runAsCommand
(
c
i
,
new
Runnable
()
{
@Override
public
void
run
()
{
fix
.
runFix
(
IConstraintUIService
.
getInstance
().
getStatus
(
c
));
fix
.
runFix
(
IConstraintUIService
.
getInstance
().
getStatus
(
c
i
));
}
});
}
}
}
/** Action for creating a new prototype. */
private
static
class
CheckFailingConstraintAction
extends
CheckUnsuccessfulConstraintAction
{
/** Action for knowing more about a failing constraint. */
private
static
class
KnowMoreAboutFailingConstraintAction
extends
KnowMoreAboutUnsuccessfulConstraintAction
{
/** Constructor. */
public
Check
FailingConstraintAction
(
ConstraintInstance
c
,
IConstrained
selectedElt
)
{
super
(
c
,
selectedElt
,
"Unsatisfied"
);
public
KnowMoreAbout
FailingConstraintAction
(
ConstraintInstance
c
i
,
IConstrained
selectedElt
)
{
super
(
c
i
,
selectedElt
,
"Unsatisfied"
);
}
}
/** Action for creating a new prototype. */
private
static
class
CheckErrorConstraintAction
extends
CheckUnsuccessfulConstraintAction
{
/** Action for knowing more about a constraint yielding an error. */
private
static
class
CheckErrorConstraintAction
extends
KnowMoreAboutUnsuccessfulConstraintAction
{
/** Constructor. */
public
CheckErrorConstraintAction
(
ConstraintInstance
c
,
IConstrained
selectedElt
)
{
super
(
c
,
selectedElt
,
"Error encountered"
);
public
CheckErrorConstraintAction
(
ConstraintInstance
c
i
,
IConstrained
selectedElt
)
{
super
(
c
i
,
selectedElt
,
"Error encountered"
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment