Skip to content
Snippets Groups Projects
Commit 127aab5e authored by Daniel Ratiu's avatar Daniel Ratiu
Browse files

small code cleanings

refs 236
parent 3e673832
No related branches found
No related tags found
No related merge requests found
...@@ -24,11 +24,12 @@ import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; ...@@ -24,11 +24,12 @@ import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/** /**
* Label provider for model elements that have corresponding handlers.
* *
* @author mou * @author mou
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: * @ConQAT.Rating GREEN Hash: 7C9C1135B33D4F3D58BEB826E63AB70A
*/ */
public class ModelElementLabelProvider extends LabelProvider { public class ModelElementLabelProvider extends LabelProvider {
/** {@inheritDoc} */ /** {@inheritDoc} */
......
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 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.kernel.ui.util;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
/**
* Utility methods for dealing with selections.
*
* This class contains slight improvements with respect to
* {@link org.conqat.ide.commons.ui.selection.SelectionUtils}.
*
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: 9641C2CB35796514DC1145D3DA0570B5
*/
public class SelectionUtils {
/**
* For a selection provider object get the selected object, for simple
* selections a cast is performed to the desired type; for a structured
* selection returns the first element or <code>null</code> if the selection
* is empty. This return <code>null</code> if the provided selection is null
* or the element is not of the required type.
*/
public static <T> T checkAndPickFirst(ISelectionProvider selectionProvider,
Class<T> type) {
return checkAndPickFirst(selectionProvider.getSelection(), type);
}
/**
* For simple selections a cast is performed to the desired type. For a
* structured selection returns the first element or <code>null</code> if
* the selection is empty. This return <code>null</code> if the provided
* selection is null or the element is not of the required type.
*/
@SuppressWarnings("unchecked")
public static <T> T checkAndPickFirst(ISelection selection, Class<T> type) {
Object selectedElement;
if (selection == null || selection.isEmpty())
return null;
if (!(selection instanceof IStructuredSelection)) {
selectedElement = selection;
} else {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
selectedElement = structuredSelection.getFirstElement();
}
if (!type.isInstance(selectedElement)) {
return null;
}
return (T) selectedElement;
}
}
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