org.reuseware.application.taipan.gmf.editor.properties.TaiPanPropertiesLabelProvider.java Source code

Java tutorial

Introduction

Here is the source code for org.reuseware.application.taipan.gmf.editor.properties.TaiPanPropertiesLabelProvider.java

Source

/*******************************************************************************
 * Copyright (c) 2006-2012
 * Software Technology Group, Dresden University of Technology
 * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   Software Technology Group - TU Dresden, Germany;
 *   DevBoost GmbH - Berlin, Germany
 *      - initial API and implementation
 ******************************************************************************/
/*
 * Copyright (c) 2006, 2007 Borland Software Corporation
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 */
package org.reuseware.application.taipan.gmf.editor.properties;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.graphics.Image;
import org.reuseware.application.taipan.gmf.editor.part.TaiPanDiagramEditorPlugin;

/**
 * @generated
 */
public class TaiPanPropertiesLabelProvider extends DecoratingLabelProvider {

    /**
     * @generated
     */
    public TaiPanPropertiesLabelProvider() {
        super(new AdapterFactoryLabelProvider(
                TaiPanDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()), null);
    }

    /**
     * @generated
     */
    public String getText(Object element) {
        Object selected = unwrap(element);
        return super.getText(selected);
    }

    /**
     * @generated
     */
    public Image getImage(Object element) {
        return super.getImage(unwrap(element));
    }

    /**
     * @generated
     */
    private Object unwrap(Object element) {
        if (element instanceof IStructuredSelection) {
            return unwrap(((IStructuredSelection) element).getFirstElement());
        }
        if (element instanceof EditPart) {
            return unwrapEditPart((EditPart) element);
        }
        if (element instanceof IAdaptable) {
            View view = (View) ((IAdaptable) element).getAdapter(View.class);
            if (view != null) {
                return unwrapView(view);
            }
        }
        return element;
    }

    /**
     * @generated
     */
    private Object unwrapEditPart(EditPart p) {
        if (p.getModel() instanceof View) {
            return unwrapView((View) p.getModel());
        }
        return p.getModel();
    }

    /**
     * @generated
     */
    private Object unwrapView(View view) {
        return view.getElement() == null ? view : view.getElement();
    }

}