Skip to content
Snippets Groups Projects
Commit 759cb1fc authored by Simon Barner's avatar Simon Barner
Browse files

- GSNPositionedEditPartBase*: Avoid code duplication by pushing...

- GSNPositionedEditPartBase*: Avoid code duplication by pushing refreshDecorationFigure() to PositionedEditPartBase
- PositionedEditPartBase.refreshDecorationFigure()
  - Avoid SWT Image leak by reusing the same icons
  - Add more null-checks to implementation
- MarkerViewPart -> column updater: Avoid SWT Image leak by disposing old image before setting a new one
parent 1a59c197
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ import static org.eclipse.gef.EditPolicy.COMPONENT_ROLE;
import static org.eclipse.gef.EditPolicy.CONNECTION_BENDPOINTS_ROLE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE;
import static org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart.DECORATION_LAYER;
import static org.fortiss.tooling.base.ui.utils.DecorationIconUtils.getMarkerServiceDecorationIcon;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUtils.getConnectionPoints;
import static org.fortiss.tooling.base.ui.utils.PropertiesViewUtils.raisePropertiesView;
......@@ -70,7 +71,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 9345FE5AF10D86F22A3FF8CD369205C8
* @ConQAT.Rating YELLOW Hash: 2DB5E3E6F5414AC369BCEAE8744C15A0
*/
public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> extends
AbstractConnectionEditPart {
......@@ -186,35 +187,26 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ex
private void refreshDecorationFigure() {
Rectangle decorationBounds = determineDecorationFigureBounds();
decorationFigure.setBounds(decorationBounds);
decorationFigure.getParent().setConstraint(decorationFigure, decorationBounds);
Image icon = null;
ESeverity sev = IMarkerService.INSTANCE.getHighestViolationSeverity(getModel());
switch(sev) {
case ERROR:
icon =
IMarkerService.INSTANCE.getImageFor(ESeverity.ERROR,
useSmallDecorationImage()).createImage();
break;
case WARNING:
icon =
IMarkerService.INSTANCE.getImageFor(ESeverity.WARNING,
useSmallDecorationImage()).createImage();
break;
default:
}
decorationFigure.setIcon(icon);
if(icon != null) {
String message = "";
Collection<IConstraintViolation<? extends EObject>> violations =
IMarkerService.INSTANCE.getViolations(getModel());
for(IConstraintViolation<? extends EObject> viol : violations) {
if(viol.getSeverity() == sev) {
message = viol.getExplanation();
break;
if(decorationFigure.getParent() != null && decorationBounds != null) {
decorationFigure.getParent().setConstraint(decorationFigure, decorationBounds);
ESeverity severity = IMarkerService.INSTANCE.getHighestViolationSeverity(getModel());
Image icon = getMarkerServiceDecorationIcon(severity, useSmallDecorationImage());
decorationFigure.setIcon(icon);
if(icon != null) {
String message = "";
Collection<IConstraintViolation<? extends EObject>> violations =
IMarkerService.INSTANCE.getViolations(getModel());
for(IConstraintViolation<? extends EObject> viol : violations) {
if(viol.getSeverity() == severity) {
message = viol.getExplanation();
break;
}
}
decorationFigure.setToolTip(new Label(message));
}
decorationFigure.setToolTip(new Label(message));
}
}
......
......@@ -19,6 +19,7 @@ package org.fortiss.tooling.base.ui.editpart;
import static org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart.DECORATION_LAYER;
import static org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart.LABEL_LAYER;
import static org.fortiss.tooling.base.ui.utils.DecorationIconUtils.getMarkerServiceDecorationIcon;
import java.util.Collection;
......@@ -35,7 +36,6 @@ import org.eclipse.gef.requests.SelectionRequest;
import org.eclipse.gef.tools.ConnectionDragCreationTool;
import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editpart.figure.TransparentLabel;
import org.fortiss.tooling.base.ui.layout.IDiagramLayoutConfiguration;
......@@ -73,7 +73,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 75854B065CE1816387777E81CF420339
* @ConQAT.Rating YELLOW Hash: 052C1F709DC1178091A3B366C58EE0BF
*/
public abstract class PositionedEditPartBase<T extends ILayoutedModelElement> extends
GraphicalEditPartBase<T> implements NodeEditPart {
......@@ -216,27 +216,16 @@ public abstract class PositionedEditPartBase<T extends ILayoutedModelElement> ex
}
/** Refreshes the decoration figure using {@link IMarkerService}. */
private void refreshDecorationFigure() {
protected void refreshDecorationFigure() {
Rectangle decorationBounds = determineDecorationFigureBounds();
decorationFigure.setBounds(decorationBounds);
decorationFigure.getParent().setConstraint(decorationFigure, decorationBounds);
if(decorationFigure.getParent() != null && decorationBounds != null) {
decorationFigure.getParent().setConstraint(decorationFigure, decorationBounds);
Image icon = null;
ESeverity sev = IMarkerService.INSTANCE.getHighestViolationSeverity(getModel());
switch(sev) {
case ERROR:
icon =
IMarkerService.INSTANCE.getImageFor(ESeverity.ERROR,
useSmallDecorationImage()).createImage();
break;
case WARNING:
icon =
IMarkerService.INSTANCE.getImageFor(ESeverity.WARNING,
useSmallDecorationImage()).createImage();
break;
default:
ESeverity severity = IMarkerService.INSTANCE.getHighestViolationSeverity(getModel());
decorationFigure.setIcon(getMarkerServiceDecorationIcon(severity,
useSmallDecorationImage()));
}
decorationFigure.setIcon(icon);
}
/** Returns the message for the given severity of the model. */
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2015 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils;
import org.eclipse.swt.graphics.Image;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity;
import org.fortiss.tooling.kernel.ui.service.IMarkerService;
/**
* Utility class to obtain decoration icons for use with the {@link IMarkerService}.
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 60BCFA87AD86A972CD3596BE3167865C
*/
public class DecorationIconUtils {
/** Cached small error icon. */
private static Image smallErrorIcon = IMarkerService.INSTANCE
.getImageFor(ESeverity.ERROR, true).createImage();
/** Cached large error icon. */
private static Image largeErrorIcon = IMarkerService.INSTANCE.getImageFor(ESeverity.ERROR,
false).createImage();
/** Cached small warning icon. */
private static Image smallWarningIcon = IMarkerService.INSTANCE.getImageFor(ESeverity.WARNING,
true).createImage();
/** Cached large warning icon. */
private static Image largeWarningIcon = IMarkerService.INSTANCE.getImageFor(ESeverity.WARNING,
false).createImage();
/**
* <p>
* Returns an {@link IMarkerService} decoration icon for the specified {@link ESeverity}.
* </p>
* <p>
* Note: The returned {@link Image} <b>must NOT</b> be disposed</b>.
* </p>
*/
public static Image getMarkerServiceDecorationIcon(ESeverity severity, boolean useSmallImage) {
switch(severity) {
case ERROR:
return useSmallImage ? smallErrorIcon : largeErrorIcon;
case WARNING:
return useSmallImage ? smallWarningIcon : largeWarningIcon;
default:
}
return null;
}
}
......@@ -35,6 +35,7 @@ import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
......@@ -52,7 +53,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 2EAB8D094E21BEEC5343D99C5404FD50
* @ConQAT.Rating YELLOW Hash: E58AC80BFD881369E9A5E8844E5AEA0D
*/
public class MarkerViewPart extends ViewPart {
......@@ -87,6 +88,10 @@ public class MarkerViewPart extends ViewPart {
public void update(ViewerCell cell) {
if(cell.getElement() instanceof ESeverity) {
cell.setText(((ESeverity)cell.getElement()).toString());
Image oldImage = cell.getImage();
if(oldImage != null) {
oldImage.dispose();
}
cell.setImage(IMarkerService.INSTANCE.getImageFor((ESeverity)cell.getElement(),
false).createImage());
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment