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
c1d65364
Commit
c1d65364
authored
8 years ago
by
Vincent Aravantinos
Browse files
Options
Downloads
Patches
Plain Diff
improves constraint context menu in case no specific error messages have been defined
refs 2553
parent
c53f12ba
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
+60
-86
60 additions, 86 deletions
...tiss/tooling/kernel/ui/internal/views/ConstraintMenu.java
with
60 additions
and
86 deletions
org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java
+
60
−
86
View file @
c1d65364
...
...
@@ -8,6 +8,7 @@
+-----------------------------------------------------------------------*/
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
;
...
...
@@ -26,12 +27,14 @@ 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.ErrorVerificationStatus
;
import
org.fortiss.tooling.kernel.model.constraints.FailVerificationStatus
;
import
org.fortiss.tooling.kernel.model.constraints.IConstrained
;
import
org.fortiss.tooling.kernel.model.constraints.IConstraint
;
import
org.fortiss.tooling.kernel.model.constraints.IConstraintVerificationStatus
;
import
org.fortiss.tooling.kernel.model.constraints.OutdatedVerificationStatus
;
import
org.fortiss.tooling.kernel.model.constraints.SuccessVerificationStatus
;
import
org.fortiss.tooling.kernel.service.ICommandStackService
;
import
org.fortiss.tooling.kernel.service.IConstraintVerificationService
;
...
...
@@ -52,7 +55,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash:
B817A3E9DF60439556DDA0454A6E1010
* @ConQAT.Rating YELLOW Hash:
6B633E486D2B054E8398EF36F0420AFB
*/
public
class
ConstraintMenu
implements
IContextMenuContributor
{
...
...
@@ -78,16 +81,23 @@ public class ConstraintMenu implements IContextMenuContributor {
*/
private
IContributionItem
constraintToAction
(
IConstraint
c
,
IConstrained
elt
)
{
IConstraintVerificationStatus
status
=
c
.
getVerificationStatus
();
ConstraintSubMenuBase
m
;
if
(
status
instanceof
FailVerificationStatus
)
{
CheckFailingConstraintAction
m
=
new
CheckFailingConstraintAction
(
c
,
elt
);
return
m
.
getItems
().
length
!=
0
?
m
:
new
ActionContributionItem
(
new
FailedAction
(
c
));
m
=
new
CheckFailingConstraintAction
(
c
,
elt
);
}
else
if
(
status
instanceof
ErrorVerificationStatus
)
{
CheckErrorConstraintAction
m
=
new
CheckErrorConstraintAction
(
c
,
elt
);
return
m
.
getItems
().
length
!=
0
?
m
:
new
ActionContributionItem
(
new
ErrorAction
(
c
));
m
=
new
CheckErrorConstraintAction
(
c
,
elt
);
}
else
{
CheckOutdatedConstraintAction
m
=
new
CheckOutdatedConstraintAction
(
c
,
elt
);
return
m
.
getItems
().
length
!=
0
?
m
:
new
ActionContributionItem
(
new
OutdatedAction
(
c
));
m
=
new
CheckOutdatedConstraintAction
(
c
,
elt
);
}
if
(
m
.
getItems
().
length
>
1
)
{
return
m
;
}
IAction
uniqueAction
=
m
.
getTopActionContribution
().
getAction
();
String
txt
=
m
.
getMenuText
();
String
newText
=
txt
.
substring
(
0
,
txt
.
length
()
-
1
)
+
" -> "
+
uniqueAction
.
getText
();
uniqueAction
.
setText
(
newText
);
uniqueAction
.
setImageDescriptor
(
m
.
getImageDescriptor
());
return
m
.
getTopActionContribution
();
}
/** {@inheritDoc} */
...
...
@@ -119,70 +129,6 @@ public class ConstraintMenu implements IContextMenuContributor {
}
}
/********************************************************************************************
* Simple actions: no submenus. Normally should not be used: every constraint verifier should
* provide sufficient information to populate the menu with decent information. But this
* provides at least a default.
*/
/** Base class. */
private
class
InformationAsAction
extends
Action
{
/** Constructor. */
public
InformationAsAction
(
IConstraint
c
,
String
prefix
,
ImageDescriptor
overlay
)
{
super
(
getName
(
c
,
prefix
),
getIcon
(
c
,
overlay
));
}
}
/** Information action for outdated constraints. */
private
class
OutdatedAction
extends
InformationAsAction
{
/** Constructor. */
public
OutdatedAction
(
IConstraint
c
)
{
super
(
c
,
"Outdated constraint: "
,
ESharedImages
.
WARNING_OVERLAY
.
getImageDescriptor
());
}
/** {@inheritDoc} */
@Override
public
void
run
()
{
MessageDialog
.
openWarning
(
Display
.
getDefault
().
getActiveShell
(),
"Outdated constraint"
,
this
.
getText
());
}
}
/** Information action for failing constraints. */
private
class
FailedAction
extends
InformationAsAction
{
/** Constructor. */
public
FailedAction
(
IConstraint
c
)
{
super
(
c
,
"Unsatisfied constraint: "
,
ESharedImages
.
ERROR_OVERLAY
.
getImageDescriptor
());
}
/** {@inheritDoc} */
@Override
public
void
run
()
{
MessageDialog
.
openError
(
Display
.
getDefault
().
getActiveShell
(),
"Unsatisfied constraint"
,
this
.
getText
());
}
}
/** Information action for failing constraints. */
private
class
ErrorAction
extends
InformationAsAction
{
/** Constructor. */
public
ErrorAction
(
IConstraint
c
)
{
super
(
c
,
"Error while checking constraint: "
,
ESharedImages
.
ERROR_OVERLAY
.
getImageDescriptor
());
}
/** {@inheritDoc} */
@Override
public
void
run
()
{
MessageDialog
.
openError
(
Display
.
getDefault
().
getActiveShell
(),
"Error while checking constraint"
,
this
.
getText
());
}
}
/** Get the icon of the prototype. */
public
static
String
getName
(
IConstraint
c
,
String
prefix
)
{
String
name
=
IModelElementHandlerService
.
INSTANCE
.
getName
(
c
);
...
...
@@ -200,10 +146,6 @@ public class ConstraintMenu implements IContextMenuContributor {
return
new
DecorationOverlayIcon
(
img
,
descriptors
);
}
/********************************************************************************************
* Submenus.
*/
/** Action for creating a new prototype. */
private
static
class
ConstraintSubMenuBase
extends
MenuManager
{
...
...
@@ -223,10 +165,8 @@ public class ConstraintMenu implements IContextMenuContributor {
ImageDescriptor
overlay
)
{
super
(
getName
(
c
,
prefix
),
getIcon
(
c
,
overlay
),
null
);
this
.
c
=
c
;
if
(
IConstraintVerificationUIService
.
INSTANCE
.
canOpen
(
c
.
getVerificationStatus
()))
{
moreInfoAction
=
new
ActionContributionItem
(
new
OpenStatusAction
());
this
.
add
(
moreInfoAction
);
}
moreInfoAction
=
new
ActionContributionItem
(
new
OpenStatusAction
());
this
.
add
(
moreInfoAction
);
for
(
ConstrainedWithChecksum
cwc
:
c
.
getConstrainedsWithChecksum
())
{
if
(!
selectedElt
.
equals
(
cwc
.
getConstrained
()))
{
this
.
add
(
new
ActionContributionItem
(
new
GoToConstrained
(
cwc
.
getConstrained
())));
...
...
@@ -234,6 +174,14 @@ public class ConstraintMenu implements IContextMenuContributor {
}
}
/**
* @return The top action contribution. Useful in case we get aware that there is only one
* contribution and we therefore want to present it without going through a submenu.
*/
public
ActionContributionItem
getTopActionContribution
()
{
return
moreInfoAction
;
}
/** Action to update a constraint. */
protected
class
OpenStatusAction
extends
Action
{
...
...
@@ -246,14 +194,40 @@ public class ConstraintMenu implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public
void
run
()
{
ICommandStackService
.
INSTANCE
.
runAsCommand
(
c
,
new
Runnable
()
{
@Override
public
void
run
()
{
IConstraintVerificationUIService
.
INSTANCE
.
openStatus
(
c
.
getVerificationStatus
());
IConstraintVerificationStatus
status
=
c
.
getVerificationStatus
();
if
(
c
.
getVerificationStatus
()
instanceof
OutdatedVerificationStatus
&&
IConstraintVerificationUIService
.
INSTANCE
.
canOpen
(
status
))
{
ICommandStackService
.
INSTANCE
.
runAsCommand
(
c
,
new
Runnable
()
{
@Override
public
void
run
()
{
IConstraintVerificationUIService
.
INSTANCE
.
openStatus
(
status
);
}
});
return
;
}
if
(
IConstraintVerificationUIService
.
INSTANCE
.
canOpen
(
status
))
{
IConstraintVerificationUIService
.
INSTANCE
.
openStatus
(
status
);
}
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
=
IModelElementHandlerService
.
INSTANCE
.
getName
(
c
);
String
fullName
=
name
==
null
?
"constraint"
:
name
;
if
(
status
instanceof
FailVerificationStatus
)
{
String
msg
=
(
name
==
null
?
"The "
:
fullName
);
msg
+=
" is not satisfied."
;
MessageDialog
.
openInformation
(
sh
,
"Unsatisfied constraint"
,
msg
);
}
else
if
(
status
instanceof
ErrorVerificationStatus
)
{
String
msg
=
"There was an error while verifying "
;
msg
+=
(
name
==
null
?
"the "
:
""
)
+
fullName
+
"."
;
openError
(
sh
,
"Error while verifying constraint"
,
msg
);
}
});
if
(
status
instanceof
OutdatedVerificationStatus
)
{
String
msg
=
(
name
==
null
?
"The "
:
fullName
)
+
" is outdated."
;
MessageDialog
.
openWarning
(
sh
,
"Outdated constraint"
,
msg
);
}
}
}
}
}
...
...
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