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

- Delegate construction of ColumnLabelProviders to LabelProviderFactory

refs 2226
parent 577d8d47
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$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.annotation.labelprovider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
import org.fortiss.tooling.base.ui.annotation.view.generic.GenericAnnotationView;
/**
* Factory to build {@link LabelProviderBase}-based {@link ColumnLabelProvider}s for the
* {@link GenericAnnotationView}.
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 9E7124D5C888F18B18D061E03339D166
*/
public class LabelProviderFactory {
/**
* Creates an {@link ColumnLabelProvider} for the given {@link IAnnotatedSpecification}.
*
* @param valueProvider
* Annotation's {@link IAnnotationValueProvider}
* @param viewPart
* {@link IAnnotationViewPart} in which the annotation will be displayed.
* @param columnViewer
* {@link ColumnViewer} used to display annotation
* @param editingSupport
* {@link EditingSupport} that has been provided for the annotation.
* @param clazz
* Annotation type
* @param specification
* Annotation instance
* @param instanceKey
* Key identifying annotation instance
*/
public static <T extends IAnnotatedSpecification> ColumnLabelProvider createLabelProvider(
IAnnotationValueProvider<T> valueProvider, IAnnotationViewPart viewPart,
ColumnViewer columnViewer, EditingSupport editingSupport,
Class<? extends IAnnotatedSpecification> clazz, T specification, String instanceKey)
throws Exception {
if(valueProvider.getAnnotationValue(specification, instanceKey) instanceof Boolean) {
return new EmulatedNativeCheckBoxLabelProvider(clazz, viewPart, instanceKey,
columnViewer);
}
return new AnnotationLabelProvider(clazz, viewPart, instanceKey, editingSupport);
}
/**
* Creates the {@link ColumnLabelProvider} without referring to the optional {@code instanceKey}
* (see
* {@link #createLabelProvider(IAnnotationValueProvider, IAnnotationViewPart, ColumnViewer, EditingSupport, Class, IAnnotatedSpecification, String)}
* .
*
* @param valueProvider
* Annotation's {@link IAnnotationValueProvider}
* @param viewPart
* {@link IAnnotationViewPart} in which the annotation will be displayed.
* @param columnViewer
* {@link ColumnViewer} used to display annotation
* @param editingSupport
* {@link EditingSupport} that has been provided for the annotation.
* @param clazz
* Annotation type
* @param specification
* Annotation instance
*/
public static <T extends IAnnotatedSpecification> ColumnLabelProvider createLabelProvider(
IAnnotationValueProvider<T> valueProvider, IAnnotationViewPart viewPart,
ColumnViewer columnViewer, EditingSupport editingSupport,
Class<? extends IAnnotatedSpecification> clazz, T specification) throws Exception {
return createLabelProvider(valueProvider, viewPart, columnViewer, editingSupport, clazz,
specification, IAnnotationValueProvider.DEFAULT_KEY);
}
}
......@@ -17,6 +17,9 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic;
import static org.fortiss.tooling.base.ui.annotation.editingsupport.EditingSupportFactory.createEditingSupport;
import static org.fortiss.tooling.base.ui.annotation.labelprovider.LabelProviderFactory.createLabelProvider;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
......@@ -47,10 +50,8 @@ import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.annotation.editingsupport.EditingSupportFactory;
import org.fortiss.tooling.base.ui.annotation.editingsupport.ElementCommentEditingSupport;
import org.fortiss.tooling.base.ui.annotation.editingsupport.ElementNameEditingSupport;
import org.fortiss.tooling.base.ui.annotation.labelprovider.AnnotationLabelProvider;
import org.fortiss.tooling.base.ui.annotation.labelprovider.ElementCommentLabelProvider;
import org.fortiss.tooling.base.ui.annotation.labelprovider.ElementNameLabelProvider;
import org.fortiss.tooling.base.ui.annotation.labelprovider.EmulatedNativeCheckBoxLabelProvider;
import org.fortiss.tooling.base.ui.annotation.view.AnnotationViewPartBase;
import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilter;
import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilterWidget;
......@@ -68,7 +69,7 @@ import org.fortiss.tooling.base.ui.annotation.view.generic.filter.AnnotationFilt
* @author eder, diewald, barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: A017D78A4C2EC0D3776FBD13FE452645
* @ConQAT.Rating YELLOW Hash: 0B21EEF430C06480D7DFEB554A4FE9FE
*/
public class GenericAnnotationView extends AnnotationViewPartBase {
/** Root composite of {@link GenericAnnotationView}. */
......@@ -369,8 +370,9 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
String specName = columnHandle.getColumnName();
tableColumn.setText(specName);
} catch(Exception e) {
System.out.println("Failed to create editing support for annotation class " +
annotationClass.getCanonicalName() + ": " + e.getMessage());
System.out.println("Failed to table viewer column for annotation class " +
annotationClass.getCanonicalName() +
((e.getMessage() != null) ? ": " + e.getMessage() + "." : "."));
}
}
......@@ -411,20 +413,13 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
String instanceKey = columnHandle.getInstanceKey();
EditingSupport editingSupport =
EditingSupportFactory.createEditingSupport(valueProvider, tableViewer,
createEditingSupport(valueProvider, tableViewer, annotationClass, specification,
instanceKey);
ColumnLabelProvider columnLabelProvider =
createLabelProvider(valueProvider, this, tableViewer, editingSupport,
annotationClass, specification, instanceKey);
ColumnLabelProvider columnLabelProvider = null;
// TODO (see #2226): Avoid this case distinction here and delegate the construction of label
// providers to a factory as well.
if(entry.getSpecificationValue(annotationClass) instanceof Boolean) {
columnLabelProvider =
new EmulatedNativeCheckBoxLabelProvider(annotationClass, this, instanceKey,
column.getViewer());
} else {
columnLabelProvider =
new AnnotationLabelProvider(annotationClass, this, instanceKey, editingSupport);
}
column.setEditingSupport(editingSupport);
column.setLabelProvider(columnLabelProvider);
......
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