package es.iiia.sgi.controls;
import javax.swing.text.StyleConstants.ColorConstants;
import org.eclipse.jface.action.ControlContribution;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.PlatformUI;
import es.iiia.sgi.editors.RenderingEditor;
import es.iiia.shapegrammar.execution.protocols.BreadthFirstProtocol;
import es.iiia.shapegrammar.execution.protocols.DepthFirstProtocol;
import es.iiia.shapegrammar.execution.protocols.SubShapeProtocol;
import es.iiia.shapegrammar.model.ShapeGrammarModel;
public class ProtocolCombo extends ControlContribution {
Combo combo;
int selectedIndex;
public ProtocolCombo(String str) {
super(str);
}
@Override
protected Control createControl(Composite parent) {
combo = new Combo(parent, SWT.NONE | SWT.DROP_DOWN | SWT.READ_ONLY);
combo.add("Breadth first");
combo.add("Depth first");
combo.add("Subshape");
combo.setTextLimit(10);
combo.select(selectedIndex);
//combo.setBackground(ColorConstants.white);
combo.setToolTipText("Rendering protocol");
combo.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
RenderingEditor editor = ((RenderingEditor) PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActiveEditor());
switch (combo.getSelectionIndex()) {
case 0:
editor.setProtocol(new BreadthFirstProtocol(
ShapeGrammarModel.ACTIVE_SHAPE_GRAMMAR, 0));
break;
case 1:
editor.setProtocol(new DepthFirstProtocol(
ShapeGrammarModel.ACTIVE_SHAPE_GRAMMAR, 0));
break;
default:
editor.setProtocol(new SubShapeProtocol(
ShapeGrammarModel.ACTIVE_SHAPE_GRAMMAR, 0, true));
}
selectedIndex = combo.getSelectionIndex();
}
});
return combo;
}
}