blob: 0a1f730ba89d783f683298bad5c3ab389652f1c5 [file] [log] [blame]
/**
* Copyright (c) 2013 Rushan Gilmullin, Florian Pirchner, Sopot Scela and others
* 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:
* Rushan Gilmullin - Initial implementation
*/
package org.eclipse.osbp.e4tools.extension;
import javax.inject.Inject;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.resources.IProject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor;
import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider;
import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.ContributionClassDialog;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
import org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl;
import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.databinding.edit.EMFEditProperties;
import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import e4modelextension.E4modelextensionPackage;
import e4modelextension.EditorPartDescriptor;
/**
* The Class EditorPartDescriptorEditor.
*/
public class EditorPartDescriptorEditor extends AbstractComponentEditor {
/** The composite. */
private Composite composite;
/** The context. */
private EMFDataBindingContext context;
/** The project. */
@Inject
@Optional
private IProject project;
/** The eclipse context. */
@Inject
private IEclipseContext eclipseContext;
/**
* Instantiates a new editor part descriptor editor.
*/
@Inject
public EditorPartDescriptorEditor() {
super();
}
/* (non-Javadoc)
* @see org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor#getLabel(java.lang.Object)
*/
@Override
public String getLabel(Object element) {
return "Editor Descriptor";
}
/* (non-Javadoc)
* @see org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor#getDetailLabel(java.lang.Object)
*/
@Override
public String getDetailLabel(Object element) {
EditorPartDescriptor desc = (EditorPartDescriptor) element;
return desc.getLabel();
}
/* (non-Javadoc)
* @see org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor#getDescription(java.lang.Object)
*/
@Override
public String getDescription(Object element) {
return "Editor Descriptor is a template for editor parts";
}
/* (non-Javadoc)
* @see org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor#doGetEditor(org.eclipse.swt.widgets.Composite, java.lang.Object)
*/
@Override
public Composite doGetEditor(Composite parent, Object object) {
if (composite == null) {
context = new EMFDataBindingContext();
composite = createForm(parent, context, getMaster());
}
getMaster().setValue(object);
return composite;
}
/**
* Creates the form.
*
* @param parent
* the parent
* @param context
* the context
* @param master
* the master
* @return the composite
*/
protected Composite createForm(Composite parent,
EMFDataBindingContext context, IObservableValue master) {
parent = new Composite(parent, SWT.NONE);
parent.setLayout(new GridLayout(3, false));
IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify);
// ------------------------------------------------------------
{
Label l = new Label(parent, SWT.NONE);
l.setText("Id");
Text t = new Text(parent, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
t.setLayoutData(gd);
context.bindValue(
textProp.observeDelayed(200, t),
EMFEditProperties
.value(getEditingDomain(),
ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID)
.observeDetail(master));
}
// ------------------------------------------------------------
{
Label l = new Label(parent, SWT.NONE);
l.setText("Label");
Text t = new Text(parent, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
t.setLayoutData(gd);
context.bindValue(
textProp.observeDelayed(200, t),
EMFEditProperties.value(getEditingDomain(),
UiPackageImpl.Literals.UI_LABEL__LABEL)
.observeDetail(master));
}
// ------------------------------------------------------------
{
Label l = new Label(parent, SWT.NONE);
l.setText("Tooltip");
Text t = new Text(parent, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
t.setLayoutData(gd);
context.bindValue(
textProp.observeDelayed(200, t),
EMFEditProperties.value(getEditingDomain(),
UiPackageImpl.Literals.UI_LABEL__TOOLTIP)
.observeDetail(master));
}
// ------------------------------------------------------------
{
Label l = new Label(parent, SWT.NONE);
l.setText("Icon URI");
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
context.bindValue(
textProp.observeDelayed(200, t),
EMFEditProperties.value(getEditingDomain(),
UiPackageImpl.Literals.UI_LABEL__ICON_URI)
.observeDetail(master));
Button b = new Button(parent, SWT.PUSH | SWT.FLAT);
b.setImage(createImage(ResourceProvider.IMG_Obj16_zoom));
b.setText("Find");
}
// ------------------------------------------------------------
{
Label l = new Label(parent, SWT.NONE);
l.setText("Content Filter");
Text t = new Text(parent, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
t.setLayoutData(gd);
context.bindValue(
textProp.observeDelayed(200, t),
EMFEditProperties
.value(getEditingDomain(),
E4modelextensionPackage.Literals.EDITOR_PART_DESCRIPTOR__URI_FILTER)
.observeDetail(master));
}
// ------------------------------------------------------------
{
Label l = new Label(parent, SWT.NONE);
l.setText("Class URI");
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
context.bindValue(
textProp.observeDelayed(200, t),
EMFEditProperties
.value(getEditingDomain(),
BasicPackageImpl.Literals.PART_DESCRIPTOR__CONTRIBUTION_URI)
.observeDetail(master));
final Button b = new Button(parent, SWT.PUSH | SWT.FLAT);
b.setImage(createImage(ResourceProvider.IMG_Obj16_zoom));
b.setText("Find");
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ContributionClassDialog dialog = new ContributionClassDialog(
b.getShell(),
eclipseContext,
getEditingDomain(),
(MPartDescriptor) getMaster().getValue(),
BasicPackageImpl.Literals.PART_DESCRIPTOR__CONTRIBUTION_URI,
Messages);
dialog.open();
}
});
}
// ------------------------------------------------------------
{
Label l = new Label(parent, SWT.NONE);
l.setText("Part Adding Logic");
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
context.bindValue(
textProp.observeDelayed(200, t),
EMFEditProperties
.value(getEditingDomain(),
E4modelextensionPackage.Literals.EDITOR_PART_DESCRIPTOR__PART_ADDING_LOGIC_URI)
.observeDetail(master));
final Button b = new Button(parent, SWT.PUSH | SWT.FLAT);
b.setImage(createImage(ResourceProvider.IMG_Obj16_zoom));
b.setText("Find");
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ContributionClassDialog dialog = new ContributionClassDialog(
b.getShell(),
eclipseContext,
getEditingDomain(),
(MPartDescriptor) getMaster().getValue(),
E4modelextensionPackage.Literals.EDITOR_PART_DESCRIPTOR__PART_ADDING_LOGIC_URI,
Messages);
dialog.open();
}
});
}
return parent;
}
/* (non-Javadoc)
* @see org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor#getChildList(java.lang.Object)
*/
@Override
public IObservableList getChildList(Object element) {
// TODO Auto-generated method stub
return null;
}
}