Skip to content
Snippets Groups Projects
Commit 5ad2abeb authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

implemented table control

parent 7b0acd23
No related branches found
No related tags found
No related merge requests found
Showing
with 580 additions and 19 deletions
de.bmotionstudio.gef.editor/icons/eclipse16/image_obj.gif

1.03 KiB

de.bmotionstudio.gef.editor/icons/eclipse16/overview_obj.gif

570 B

de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps.gif

343 B

de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps2.gif

335 B

de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps3.gif

336 B

de.bmotionstudio.gef.editor/icons/icon_table.gif

343 B

......@@ -166,7 +166,7 @@
</group>
<control
groupid="de.bmotionstudio.gef.editor.group.main"
icon="icons/icon_image.gif"
icon="icons/eclipse16/image_obj.gif"
id="de.bmotionstudio.gef.editor.image"
name="Image"
service="de.bmotionstudio.gef.editor.service.BImageService">
......@@ -194,7 +194,7 @@
</control>
<control
groupid="de.bmotionstudio.gef.editor.group.main"
icon="icons/icon_composite.gif"
icon="icons/eclipse16/overview_obj.gif"
id="de.bmotionstudio.gef.editor.composite"
name="Composite"
service="de.bmotionstudio.gef.editor.service.BCompositeService">
......@@ -234,6 +234,27 @@
name="Connection"
service="de.bmotionstudio.gef.editor.service.BConnectionService">
</control>
<control
groupid="de.bmotionstudio.gef.editor.group.main"
icon="icons/eclipse16/prop_ps.gif"
id="de.bmotionstudio.gef.editor.table"
name="Table"
service="de.bmotionstudio.gef.editor.service.BTableService">
</control>
<control
groupid="de.bmotionstudio.gef.editor.group.main"
icon="icons/eclipse16/prop_ps2.gif"
id="de.bmotionstudio.gef.editor.tablecolumn"
name="Column"
service="de.bmotionstudio.gef.editor.service.BTableColumnService">
</control>
<control
groupid="de.bmotionstudio.gef.editor.group.main"
icon="icons/eclipse16/prop_ps3.gif"
id="de.bmotionstudio.gef.editor.tablecell"
name="Cell"
service="de.bmotionstudio.gef.editor.service.BTableCellService">
</control>
</extension>
<extension
point="de.bmotionstudio.gef.editor.observer">
......@@ -269,6 +290,10 @@
class="de.bmotionstudio.gef.editor.observer.ExternalObserverScript"
name="External Observer Script">
</observer>
<observer
class="de.bmotionstudio.gef.editor.observer.ColumnObserver"
name="Column Observer">
</observer>
</extension>
<extension
point="de.bmotionstudio.gef.editor.schedulerEvent">
......@@ -349,6 +374,12 @@
<control
id="de.bmotionstudio.gef.editor.connection">
</control>
<control
id="de.bmotionstudio.gef.editor.tablecell">
</control>
<control
id="de.bmotionstudio.gef.editor.table">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates">
......@@ -379,6 +410,9 @@
<control
id="de.bmotionstudio.gef.editor.ellipse">
</control>
<control
id="de.bmotionstudio.gef.editor.table">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay">
......@@ -394,6 +428,9 @@
<control
id="de.bmotionstudio.gef.editor.button">
</control>
<control
id="de.bmotionstudio.gef.editor.tablecell">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SetAttribute">
......@@ -427,6 +464,12 @@
<control
id="de.bmotionstudio.gef.editor.textfield">
</control>
<control
id="de.bmotionstudio.gef.editor.tablecell">
</control>
<control
id="de.bmotionstudio.gef.editor.table">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates">
......@@ -469,6 +512,12 @@
<control
id="de.bmotionstudio.gef.editor.textfield">
</control>
<control
id="de.bmotionstudio.gef.editor.tablecell">
</control>
<control
id="de.bmotionstudio.gef.editor.table">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.SwitchImage">
......@@ -485,6 +534,12 @@
id="de.bmotionstudio.gef.editor.ellipse">
</control>
</observer>
<observer
id="de.bmotionstudio.gef.editor.observer.ColumnObserver">
<control
id="de.bmotionstudio.gef.editor.tablecolumn">
</control>
</observer>
</include>
</extension>
</plugin>
......@@ -174,7 +174,9 @@ public class AppContextMenuProvider extends ContextMenuProvider {
String langID = configurationElement
.getAttribute("language");
if (langID.equals(control.getVisualization().getLanguage())) {
if (langID != null
&& langID.equals(control.getVisualization()
.getLanguage())) {
for (IConfigurationElement cObserver : configurationElement
.getChildren("observer")) {
......
......@@ -16,6 +16,9 @@ public final class AttributeConstants {
public static final String ATTRIBUTE_ID = "de.bmotionstudio.gef.editor.attribute.BAttributeID";
public static final String ATTRIBUTE_VISIBLE = "de.bmotionstudio.gef.editor.attribute.BAttributeVisible";
public static final String ATTRIBUTE_COLUMNS = "de.bmotionstudio.gef.editor.attribute.BAttributeColumns";
public static final String ATTRIBUTE_ROWS = "de.bmotionstudio.gef.editor.attribute.BAttributeRows";
public static final String ATTRIBUTE_BACKGROUND_IMAGE = "de.bmotionstudio.gef.editor.attribute.BAttributeImage";
public static final String ATTRIBUTE_BACKGROUND_COLOR = "de.bmotionstudio.gef.editor.attribute.BAttributeBackgroundColor";
public static final String ATTRIBUTE_FOREGROUND_COLOR = "de.bmotionstudio.gef.editor.attribute.BAttributeForegroundColor";
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.attribute;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.property.IntegerPropertyDescriptor;
public class BAttributeColumns extends AbstractAttribute {
public BAttributeColumns(Object value) {
super(value);
}
public PropertyDescriptor preparePropertyDescriptor() {
IntegerPropertyDescriptor descriptor = new IntegerPropertyDescriptor(
getID(), getName());
return descriptor;
}
@Override
public String validateValue(Object value, BControl control) {
if (!(String.valueOf(value)).trim().matches("\\d*")) {
return "Value must be a number";
}
if ((String.valueOf(value)).trim().length() == 0) {
return "Value must not be empty string";
}
return null;
}
@Override
public String getName() {
return "Columns";
}
}
......@@ -27,9 +27,12 @@ public class BAttributeCoordinates extends AbstractAttribute {
Point point = (Point) element;
StringBuffer buf = new StringBuffer();
buf.append("[");
if (point.x >= 0)
buf.append(point.x);
if (point.y >= 0) {
buf.append(", ");
buf.append(point.y);
}
buf.append("]");
return buf.toString();
}
......@@ -39,11 +42,22 @@ public class BAttributeCoordinates extends AbstractAttribute {
@Override
public Object getEditableValue() {
int x = Integer.valueOf(getChildren()
.get(AttributeConstants.ATTRIBUTE_X).getValue().toString());
int y = Integer.valueOf(getChildren()
.get(AttributeConstants.ATTRIBUTE_Y).getValue().toString());
AbstractAttribute atrX = getChildren().get(
AttributeConstants.ATTRIBUTE_X);
AbstractAttribute atrY = getChildren().get(
AttributeConstants.ATTRIBUTE_Y);
int x = -1;
int y = -1;
if (atrX != null)
x = Integer.valueOf(atrX.getValue().toString());
if (atrY != null)
y = Integer.valueOf(atrY.getValue().toString());
return new Point(x, y);
}
@Override
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.attribute;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.property.IntegerPropertyDescriptor;
public class BAttributeRows extends AbstractAttribute {
public BAttributeRows(Object value) {
super(value);
}
public PropertyDescriptor preparePropertyDescriptor() {
IntegerPropertyDescriptor descriptor = new IntegerPropertyDescriptor(
getID(), getName());
return descriptor;
}
@Override
public String validateValue(Object value, BControl control) {
if (!(String.valueOf(value)).trim().matches("\\d*")) {
return "Value must be a number";
}
if ((String.valueOf(value)).trim().length() == 0) {
return "Value must not be empty string";
}
return null;
}
@Override
public String getName() {
return "Rows";
}
}
......@@ -27,9 +27,12 @@ public class BAttributeSize extends AbstractAttribute {
Point point = (Point) element;
StringBuffer buf = new StringBuffer();
buf.append("[");
if (point.x >= 0)
buf.append(point.x);
if (point.y >= 0) {
buf.append(", ");
buf.append(point.y);
}
buf.append("]");
return buf.toString();
}
......@@ -39,12 +42,22 @@ public class BAttributeSize extends AbstractAttribute {
@Override
public Object getEditableValue() {
int width = Integer.valueOf(getChildren()
.get(AttributeConstants.ATTRIBUTE_WIDTH).getValue().toString());
int height = Integer
.valueOf(getChildren().get(AttributeConstants.ATTRIBUTE_HEIGHT)
.getValue().toString());
AbstractAttribute atrWidth = getChildren().get(
AttributeConstants.ATTRIBUTE_WIDTH);
AbstractAttribute atrHeight = getChildren().get(
AttributeConstants.ATTRIBUTE_HEIGHT);
int width = -1;
int height = -1;
if (atrWidth != null)
width = Integer.valueOf(atrWidth.getValue().toString());
if (atrHeight != null)
height = Integer.valueOf(atrHeight.getValue().toString());
return new Point(width, height);
}
@Override
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.command;
import de.bmotionstudio.gef.editor.model.BControl;
public class AddCommand extends org.eclipse.gef.commands.Command {
private BControl child;
private BControl parent;
private int index = -1;
public AddCommand() {
super("Add Control");
}
public void execute() {
if (index < 0)
parent.addChild(child);
else
parent.addChild(child, index);
}
public BControl getParent() {
return parent;
}
public void redo() {
if (index < 0)
parent.addChild(child);
else
parent.addChild(child, index);
}
public void setChild(BControl subpart) {
child = subpart;
}
public void setIndex(int i) {
index = i;
}
public void setParent(BControl newParent) {
parent = newParent;
}
public void undo() {
parent.removeChild(child);
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.command;
import org.eclipse.gef.commands.Command;
import de.bmotionstudio.gef.editor.model.BControl;
public class ReorderPartCommand extends Command {
private int oldIndex, newIndex;
private BControl child;
private BControl parent;
public ReorderPartCommand(BControl child, BControl parent, int newIndex) {
super("Reorder Control");
this.child = child;
this.parent = parent;
this.newIndex = newIndex;
}
public void execute() {
oldIndex = parent.getChildrenArray().indexOf(child);
parent.removeChild(child);
parent.addChild(child, newIndex);
}
public void undo() {
parent.removeChild(child);
parent.addChild(child, oldIndex);
}
}
......@@ -23,8 +23,8 @@ import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.BAttributeHeight;
import de.bmotionstudio.gef.editor.attribute.BAttributeWidth;
import de.bmotionstudio.gef.editor.command.BControlChangeLayoutCommand;
import de.bmotionstudio.gef.editor.command.CreateCommand;
import de.bmotionstudio.gef.editor.command.ChangeGuideCommand;
import de.bmotionstudio.gef.editor.command.CreateCommand;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.model.BMotionGuide;
import de.bmotionstudio.gef.editor.part.AppAbstractEditPart;
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.editpolicy;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.FlowLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import de.bmotionstudio.gef.editor.command.AddCommand;
import de.bmotionstudio.gef.editor.command.ReorderPartCommand;
import de.bmotionstudio.gef.editor.model.BControl;
import de.bmotionstudio.gef.editor.model.BTable;
import de.bmotionstudio.gef.editor.model.BTableCell;
import de.bmotionstudio.gef.editor.model.BTableColumn;
public class BMotionStudioFlowEditPolicy extends FlowLayoutEditPolicy {
@Override
protected Command createAddCommand(EditPart child, EditPart after) {
BControl childModel = (BControl) child.getModel();
BControl parentModel = (BControl) getHost().getModel();
if ((childModel instanceof BTableColumn && parentModel instanceof BTable)
|| (childModel instanceof BTableCell
&& parentModel instanceof BTableColumn && childModel
.getParent().equals(parentModel))) {
AddCommand command = new AddCommand();
command.setChild(childModel);
command.setParent(parentModel);
int index = getHost().getChildren().indexOf(after);
command.setIndex(index);
return command;
}
return null;
}
/**
* @see org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
*/
protected EditPolicy createChildEditPolicy(EditPart child) {
BMotionStudioResizableEditPolicy policy = new BMotionStudioResizableEditPolicy();
policy.setResizeDirections(PositionConstants.EAST
| PositionConstants.WEST);
return policy;
}
@Override
protected Command createMoveChildCommand(EditPart child, EditPart after) {
BControl childModel = (BControl) child.getModel();
BControl parentModel = (BControl) getHost().getModel();
if ((childModel instanceof BTableColumn && parentModel instanceof BTable)
|| (childModel instanceof BTableCell && parentModel instanceof BTableColumn)) {
int oldIndex = getHost().getChildren().indexOf(child);
int newIndex = getHost().getChildren().indexOf(after);
if (newIndex > oldIndex)
newIndex--;
ReorderPartCommand command = new ReorderPartCommand(childModel,
parentModel, newIndex);
return command;
}
return null;
}
@Override
protected Command getCreateCommand(CreateRequest request) {
// CreateCommand command = new CreateCommand(
// (BControl) request.getNewObject(), (BControl) getHost()
// .getModel());
// EditPart after = getInsertionReference(request);
// command.setLayout(new Rectangle(0, 0, 100, 25));
// int index = getHost().getChildren().indexOf(after);
// command.setIndex(index);
// return command;
return null;
}
@Override
protected boolean isHorizontal() {
IFigure figure = getLayoutContainer();
if (figure.getLayoutManager() instanceof ToolbarLayout) {
return ((ToolbarLayout) figure.getLayoutManager()).isHorizontal();
} else if (figure.getLayoutManager() instanceof FlowLayout) {
return ((FlowLayout) figure.getLayoutManager()).isHorizontal();
}
return false;
}
@Override
public void showLayoutTargetFeedback(Request request) {
if (request instanceof CreateRequest) {
Object newObject = ((CreateRequest) request).getNewObject();
if (!(newObject instanceof BTableColumn || newObject instanceof BTableCell))
return;
}
super.showLayoutTargetFeedback(request);
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.editpolicy;
import java.util.Iterator;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
public class BMotionStudioResizableEditPolicy extends ResizableEditPolicy {
/**
* Creates the figure used for feedback.
*
* @return the new feedback figure
*/
protected IFigure createDragSourceFeedbackFigure() {
IFigure figure = createFigure((GraphicalEditPart) getHost(), null);
figure.setBounds(getInitialFeedbackBounds());
addFeedback(figure);
return figure;
}
protected IFigure createFigure(GraphicalEditPart part, IFigure parent) {
IFigure child = getCustomFeedbackFigure(part.getModel());
if (parent != null)
parent.add(child);
Rectangle childBounds = part.getFigure().getBounds().getCopy();
IFigure walker = part.getFigure().getParent();
while (walker != ((GraphicalEditPart) part.getParent()).getFigure()) {
walker.translateToParent(childBounds);
walker = walker.getParent();
}
child.setBounds(childBounds);
Iterator<?> i = part.getChildren().iterator();
while (i.hasNext())
createFigure((GraphicalEditPart) i.next(), child);
return child;
}
protected IFigure getCustomFeedbackFigure(Object modelPart) {
IFigure figure;
figure = new RectangleFigure();
((RectangleFigure) figure).setXOR(true);
((RectangleFigure) figure).setFill(true);
figure.setBackgroundColor(ColorConstants.blue);
figure.setForegroundColor(ColorConstants.white);
return figure;
}
/**
* Returns the layer used for displaying feedback.
*
* @return the feedback layer
*/
protected IFigure getFeedbackLayer() {
return getLayer(LayerConstants.SCALED_FEEDBACK_LAYER);
}
/**
* @see org.eclipse.gef.editpolicies.NonResizableEditPolicy#getInitialFeedbackBounds()
*/
protected Rectangle getInitialFeedbackBounds() {
return getHostFigure().getBounds();
}
}
package de.bmotionstudio.gef.editor.figure;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
public class AbstractTableFigure extends AbstractBMotionFigure {
private Color foregroundColor;
@Override
public Color getForegroundColor() {
return foregroundColor;
}
public void setForegroundColor(RGB rgb) {
if (foregroundColor != null)
foregroundColor.dispose();
this.foregroundColor = new Color(Display.getDefault(), rgb);
repaint();
}
@Override
public void deactivateFigure() {
if (foregroundColor != null)
foregroundColor.dispose();
}
}
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.bmotionstudio.gef.editor.figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
public class TableCellFigure extends AbstractTableFigure {
private String text;
private Color backgroundColor;
private Color textColor;
public TableCellFigure() {
setOpaque(true);
}
@Override
protected void paintBorder(Graphics g) {
Rectangle r = getClientArea();
g.setBackgroundColor(backgroundColor);
g.fillRectangle(r.x, r.y, r.x + r.width, r.y + r.height);
g.setForegroundColor(textColor);
g.drawText(text, r.x + 3, r.y + 3);
Color foregroundColor = getForegroundColor();
if (foregroundColor != null)
g.setForegroundColor(foregroundColor);
g.drawLine(r.x, r.y, r.x + r.width, r.y);
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
repaint();
}
public void setBackgroundColor(RGB rgb) {
if (backgroundColor != null)
backgroundColor.dispose();
backgroundColor = new Color(Display.getDefault(), rgb);
repaint();
}
public void setTextColor(RGB rgb) {
if (textColor != null)
textColor.dispose();
textColor = new Color(Display.getDefault(), rgb);
repaint();
}
@Override
public void deactivateFigure() {
if (backgroundColor != null)
backgroundColor.dispose();
if (textColor != null)
textColor.dispose();
super.deactivateFigure();
}
public void setFont(String string) {
// TODO Auto-generated method stub
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment