Commit 003305ee authored by Simon Barner's avatar Simon Barner
Browse files

Move getName() and getIcon() to KernelUIUtils.

refs 3191
parent ef474c3d
AllocationTableEditor.java a730c13e6adbc226dccf5bca44e623ff36a25512 YELLOW
AllocationTableEditorUtils.java 3f53fc3ce279be40ca18d6d63f3f7f830ec4eb86 YELLOW
ModelListenerEditorBase.java 422273b832625f15c28390c07fb0ab8167741b0f YELLOW
ModelListenerEditorBase.java 231089cfa54ccfdd9919201373a338df88b0a11d YELLOW
ParameterTableEditor.java 10b1d1d3c05f75f9ad4d7f7031fe69d733894919 YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2017 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.af3.allocation.ui.editor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swt.graphics.Image;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* Utility methods for {@link AllocationTableEditor}.
*
* @author barner
*/
public class AllocationTableEditorUtils {
// TODO Move to a more general utility class after the release
/**
* Returns a UI name for the given {@code element}, or {@code null} in case it cannot be
* determined.
*/
public static String getName(Object element) {
if(!(element instanceof EObject)) {
return null;
}
EObject eObject = (EObject)element;
IModelElementHandler<EObject> modelElementHandler =
IModelElementHandlerService.getInstance().getModelElementHandler(eObject);
if(modelElementHandler != null) {
return modelElementHandler.getName(eObject);
} else if(element instanceof INamedElement) {
return ((INamedElement)element).getName();
}
return null;
}
// TODO Move to a more general utility class after the release
/**
* Returns an {@link Image} for the given {@code element}, or {@code null} in case it cannot be
* determined.
*/
public static Image getImage(Object element) {
if(element instanceof EObject) {
EObject eObj = (EObject)element;
IModelElementHandler<EObject> modelElementHandler =
IModelElementHandlerService.getInstance().getModelElementHandler(eObj);
if(modelElementHandler != null) {
return modelElementHandler.getIcon(eObj);
}
}
return null;
}
}
......@@ -49,6 +49,7 @@ import org.fortiss.af3.project.utils.ProjectUtils;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.editor.GEFEditorBase;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
import org.fortiss.tooling.kernel.ui.util.KernelUIUtils;
/**
* Base class for model editors that listen for changes in other parts of the model.
......@@ -254,7 +255,7 @@ public abstract class ModelListenerEditorBase<T extends EObject> extends GEFEdit
/** {@inheritDoc} */
@Override
public String getText(Object element) {
return AllocationTableEditorUtils.getName(element);
return KernelUIUtils.getName(element);
}
});
......
ParameterEntryTreeViewerEditingSupport.java 759d5a5462aef5ec2ccd5e0b61b5858d3196145a GREEN
ParameterEntryTreeViewerLabelProvider.java c6cd26de2d483a43f013893d0feff158e7cdb1bf GREEN
ParameterSourceElementTreeViewerEditingSupport.java ec180b48e1cb32068c9eab5d60dd4b35fb91899c GREEN
ParameterSourceElementTreeViewerLabelProvider.java e2dbecb997ee8e283cd6eb9f91a882a8ec7b75e9 GREEN
ParameterEntryTreeViewerLabelProvider.java b7d60c50c0c98bbd862cb092981408e8ca93af32 GREEN
ParameterSourceElementTreeViewerEditingSupport.java e1aa243eb4dd924ba79bc73ebf82bdd16b6a1543 GREEN
ParameterSourceElementTreeViewerLabelProvider.java cc7c7b11e0d74a3f5c5a68fa1b82885962e797b4 GREEN
ParameterTableTreeViewerManager.java d1205500f59668b6b2083295bdade48844bd60f8 GREEN
TreeViewerCheckBoxEditingSupport.java ae801bf9e495b983774224444549cfc8c26fee58 GREEN
TreeViewerCheckBoxLabelProvider.java 6cb338ada7c286ae7aaedc3a9f326136571daf81 GREEN
TreeViewerCheckBoxLabelProvider.java 4ef8bf1d20be01aaf9e62db25a25e48f3954bebf GREEN
TreeViewerContentProvider.java 6b97e361c3c8a633eb29963d44f7d4b3a9b9089a GREEN
TreeViewerFirstColumnLabelProvider.java 58071eb18cad8bf7c48beffda449f6eef22906a3 GREEN
TreeViewerManager.java 8c5f63f46322abd0946c5f80ab6fc356ae4bbe73 GREEN
TreeViewerFirstColumnLabelProvider.java 667f74dd10c1eebfb62976f846ff555b9da77988 GREEN
TreeViewerManager.java 804bfed104c725406d1da3e2fcabdb9bdeceee8b GREEN
......@@ -16,7 +16,6 @@
package org.fortiss.af3.allocation.ui.editor.treeviewer;
import static org.fortiss.af3.allocation.ui.DefaultStyle.RIGHT_ARROW;
import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getParameterEntryName;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getParameterEntryValue;
......@@ -28,6 +27,7 @@ import org.fortiss.af3.allocation.model.ParameterEntry;
import org.fortiss.af3.allocation.model.ParameterTable;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.ui.util.KernelUIUtils;
/**
* Label provider to display {@link ParameterEntry}s.
......@@ -97,8 +97,9 @@ public class ParameterEntryTreeViewerLabelProvider<T extends ParameterTable> ext
public String getToolTipText(Object object) {
if(object instanceof IModelElement) {
IModelElement sourceElement = (IModelElement)object;
return getParameterToolTipLabelPrefix(sourceElement) + getName(sourceElement) + " " +
"\n" + RIGHT_ARROW + "\n" + getName(targetElement);
return getParameterToolTipLabelPrefix(sourceElement) +
KernelUIUtils.getName(sourceElement) + " " + "\n" + RIGHT_ARROW + "\n" +
KernelUIUtils.getName(targetElement);
}
return null;
}
......
......@@ -15,7 +15,6 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.allocation.ui.editor.treeviewer;
import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.ParameterTableTreeViewerManager.getAnnotationType;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.runAsCommand;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
......@@ -32,6 +31,7 @@ import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.ui.util.KernelUIUtils;
/**
* {@link EditingSupport} to enable editing parameter annotations of source entity types
......@@ -112,7 +112,7 @@ public class ParameterSourceElementTreeViewerEditingSupport extends EditingSuppo
error(AF3AllocationActivator.getDefault(),
"Error setting source entity annotation of type " +
annotationType.getSimpleName() + " for " +
getName(element), e);
KernelUIUtils.getName(element), e);
}
});
getViewer().refresh(true);
......
......@@ -15,7 +15,6 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.allocation.ui.editor.treeviewer;
import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.ParameterTableTreeViewerManager.getAnnotationName;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.ParameterTableTreeViewerManager.getAnnotationType;
......@@ -26,6 +25,7 @@ import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.ui.util.KernelUIUtils;
/**
* {@link ColumnLabelProvider} to enable editing parameter annotations of source entity types
......@@ -70,7 +70,8 @@ public class ParameterSourceElementTreeViewerLabelProvider extends ColumnLabelPr
public String getToolTipText(Object object) {
if(object instanceof IModelElement && sourceEntityType.isAssignableFrom(object.getClass())) {
IModelElement element = (IModelElement)object;
return getAnnotationName(element, annotationType) + " of " + getName(element);
return getAnnotationName(element, annotationType) + " of " +
KernelUIUtils.getName(element);
}
return null;
}
......
......@@ -16,7 +16,6 @@
package org.fortiss.af3.allocation.ui.editor.treeviewer;
import static org.fortiss.af3.allocation.ui.DefaultStyle.RIGHT_ARROW;
import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.utils.AllocationUtils.isAllocated;
import static org.fortiss.af3.allocation.utils.AllocationUtils.isModifiableAllocationEntry;
......@@ -26,6 +25,7 @@ import org.fortiss.af3.allocation.model.AllocationEntry;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider;
import org.fortiss.tooling.kernel.ui.util.KernelUIUtils;
/**
* Label provider to display {@link AllocationTable}'s entries.
......@@ -93,7 +93,8 @@ public class TreeViewerCheckBoxLabelProvider<T extends AllocationTable> extends
@Override
public String getToolTipText(Object object) {
if(object instanceof IModelElement) {
return getName(object) + " " + "\n" + RIGHT_ARROW + "\n" + getName(targetElement);
return KernelUIUtils.getName(object) + " " + "\n" + RIGHT_ARROW + "\n" +
KernelUIUtils.getName(targetElement);
}
return null;
}
......
......@@ -17,7 +17,6 @@ package org.fortiss.af3.allocation.ui.editor.treeviewer;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.getName;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.TreeViewerManager.ROW_LABEL_INDENT;
import static org.fortiss.af3.allocation.ui.editor.treeviewer.TreeViewerManager.ROW_LABEL_OFFSET;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.computeFullyQualifiedName;
......@@ -32,9 +31,9 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.ui.editor.AllocationTableEditor;
import org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.ui.util.KernelUIUtils;
/**
* Label provider for {@link TreeViewer}'s first column.
......@@ -85,7 +84,7 @@ public class TreeViewerFirstColumnLabelProvider<T extends AllocationTable> exten
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
return AllocationTableEditorUtils.getImage(element);
return KernelUIUtils.getImage(element);
}
/** {@inheritDoc} */
......@@ -116,7 +115,7 @@ public class TreeViewerFirstColumnLabelProvider<T extends AllocationTable> exten
if(showContainerName) {
label = getNameWithContainer(element);
} else {
label = getName(element);
label = KernelUIUtils.getName(element);
}
boolean trimLeft =
......@@ -144,10 +143,10 @@ public class TreeViewerFirstColumnLabelProvider<T extends AllocationTable> exten
if(element instanceof IConnector) {
EObject container = ((IConnector)element).eContainer();
if(container != null) {
containerName = getName(container);
containerName = KernelUIUtils.getName(container);
}
}
String elementName = getName(element);
String elementName = KernelUIUtils.getName(element);
if(elementName != null) {
return containerName != null ? containerName + "." + elementName : elementName;
......
......@@ -18,7 +18,6 @@ package org.fortiss.af3.allocation.ui.editor.treeviewer;
import static java.util.Collections.emptyList;
import static org.fortiss.af3.allocation.ui.DefaultStyle.DOWN_ARROW;
import static org.fortiss.af3.allocation.ui.DefaultStyle.RIGHT_ARROW;
import static org.fortiss.af3.allocation.ui.editor.AllocationTableEditorUtils.getImage;
import java.util.List;
......@@ -37,6 +36,7 @@ import org.fortiss.af3.allocation.model.AllocationTable;
import org.fortiss.af3.allocation.ui.editor.AllocationTableEditor;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.ui.util.KernelUIUtils;
/**
* Manages a {@link TreeViewer} to show and edit entries of {@link AllocationTable}s.
......@@ -159,7 +159,7 @@ public class TreeViewerManager<T extends AllocationTable> {
getColumnLabel(ENTRY_COLUMN_DEFAULT_WIDTH, targetElement, showContainerName,
firstColumnLabelProvider);
final String toolTipText = firstColumnLabelProvider.getToolTipText(targetElement);
final Image image = getImage(targetElement);
final Image image = KernelUIUtils.getImage(targetElement);
final ColumnLabelProvider labelProvider =
createColumnLabelProvider(allocationTable,
allocationTableEditor.getAllocationEntryType(),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment