blob: 786955f7dc3d6eb9064342c4dc6f052b2b6c4a77 [file] [log] [blame]
package org.eclipse.e4.demo.tools.simpleide;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.tools.emf.ui.internal.Messages;
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.demo.simpleide.model.simpleide.MEditorPartDescriptor;
import org.eclipse.e4.demo.simpleide.model.simpleide.impl.SimpleidePackageImpl;
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.ControlFactory;
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;
public class EditorPartDescriptorEditor extends AbstractComponentEditor {
private Composite composite;
private EMFDataBindingContext context;
@Inject
@Optional
private IProject project;
@Inject
public EditorPartDescriptorEditor() {
super();
}
@Override
public Image getImage(Object element, Display display) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getLabel(Object element) {
return "Editor Descriptor";
}
@Override
public String getDetailLabel(Object element) {
MEditorPartDescriptor desc = (MEditorPartDescriptor) element;
return desc.getLabel();
}
@Override
public String getDescription(Object element) {
return "Editor Descriptor Bla Bla Bla Bla Bla";
}
@Override
public Composite doGetEditor(Composite parent, Object object) {
if( composite == null ) {
context = new EMFDataBindingContext();
composite = createForm(parent,context, getMaster());
}
getMaster().setValue(object);
return 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("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(), SimpleidePackageImpl.Literals.EDITOR_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(),project,getEditingDomain(),(MPartDescriptor) getMaster().getValue(), BasicPackageImpl.Literals.PART_DESCRIPTOR__CONTRIBUTION_URI, Messages);
dialog.open();
}
});
}
// ------------------------------------------------------------
{
ControlFactory.createStringListWidget(parent, Messages, this, "File extensions", SimpleidePackageImpl.Literals.EDITOR_PART_DESCRIPTOR__FILEEXTENSIONS, 10);
}
return parent;
}
@Override
public IObservableList getChildList(Object element) {
// TODO Auto-generated method stub
return null;
}
}