Skip to content

Commit

Permalink
Comnine line width sections and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Aug 20, 2023
1 parent a2d17a3 commit 6e61283
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
import com.archimatetool.editor.diagram.actions.BorderColorAction;
import com.archimatetool.editor.diagram.actions.BringForwardAction;
import com.archimatetool.editor.diagram.actions.BringToFrontAction;
import com.archimatetool.editor.diagram.actions.ConnectionLineWidthAction;
import com.archimatetool.editor.diagram.actions.LineWidthAction;
import com.archimatetool.editor.diagram.actions.ConnectionRouterAction;
import com.archimatetool.editor.diagram.actions.CopyAction;
import com.archimatetool.editor.diagram.actions.CutAction;
Expand Down Expand Up @@ -828,7 +828,7 @@ protected void createActions(GraphicalViewer viewer) {
getUpdateCommandStackActions().add((UpdateAction)action);

// Connection Line Width
action = new ConnectionLineWidthAction(this);
action = new LineWidthAction(this);
registry.registerAction(action);
getSelectionActions().add(action.getId());
getUpdateCommandStackActions().add((UpdateAction)action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.archimatetool.editor.diagram.actions.BorderColorAction;
import com.archimatetool.editor.diagram.actions.BringForwardAction;
import com.archimatetool.editor.diagram.actions.BringToFrontAction;
import com.archimatetool.editor.diagram.actions.ConnectionLineWidthAction;
import com.archimatetool.editor.diagram.actions.LineWidthAction;
import com.archimatetool.editor.diagram.actions.ConnectionRouterAction;
import com.archimatetool.editor.diagram.actions.DefaultEditPartSizeAction;
import com.archimatetool.editor.diagram.actions.ExportAsImageAction;
Expand Down Expand Up @@ -146,7 +146,7 @@ protected void buildActions() {

// Fill color, line width, font, color, opacity
addRetargetAction(new RetargetAction(FillColorAction.ID, FillColorAction.TEXT));
addRetargetAction(new RetargetAction(ConnectionLineWidthAction.ID, ConnectionLineWidthAction.TEXT));
addRetargetAction(new RetargetAction(LineWidthAction.ID, LineWidthAction.TEXT));
addRetargetAction(new RetargetAction(LineColorAction.ID, LineColorAction.TEXT));
addRetargetAction(new RetargetAction(FontAction.ID, FontAction.TEXT));
addRetargetAction(new RetargetAction(FontColorAction.ID, FontColorAction.TEXT));
Expand Down Expand Up @@ -308,7 +308,7 @@ protected IMenuManager contributeToEditMenu(IMenuManager menuManager) {
editMenu.appendToGroup(GROUP_EDIT_MENU, getAction(OutlineOpacityAction.ID));

// Connection Line Width and Color
editMenu.appendToGroup(GROUP_EDIT_MENU, getAction(ConnectionLineWidthAction.ID));
editMenu.appendToGroup(GROUP_EDIT_MENU, getAction(LineWidthAction.ID));
editMenu.appendToGroup(GROUP_EDIT_MENU, getAction(LineColorAction.ID));

// Font
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,26 @@
import org.eclipse.ui.IWorkbenchPart;

import com.archimatetool.editor.diagram.commands.LineWidthCommand;
import com.archimatetool.editor.propertysections.DiagramConnectionSection;
import com.archimatetool.editor.ui.factory.ObjectUIFactory;
import com.archimatetool.editor.propertysections.LineWidthSection;
import com.archimatetool.editor.ui.factory.IObjectUIProvider;
import com.archimatetool.editor.ui.factory.ObjectUIFactory;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelConnection;
import com.archimatetool.model.ILineObject;
import com.archimatetool.model.ILockable;



/**
* Fill Color Action
* Line Width Action
*
* @author Phillip Beauvoir
*/
public class ConnectionLineWidthAction extends SelectionAction {
public class LineWidthAction extends SelectionAction {

public static final String ID = "ConnectionLineWidthAction"; //$NON-NLS-1$
public static final String TEXT = Messages.ConnectionLineWidthAction_0;
public static final String ID = "LineWidthAction"; //$NON-NLS-1$
public static final String TEXT = Messages.LineWidthAction_0;

public ConnectionLineWidthAction(IWorkbenchPart part) {
public LineWidthAction(IWorkbenchPart part) {
super(part);
setText(TEXT);
setId(ID);
Expand Down Expand Up @@ -85,7 +84,7 @@ public void run() {
}

private Command createCommand(List<?> selection, int newLineWidth) {
CompoundCommand result = new CompoundCommand(Messages.ConnectionLineWidthAction_1);
CompoundCommand result = new CompoundCommand(Messages.LineWidthAction_1);

for(Object object : selection) {
if(object instanceof EditPart) {
Expand All @@ -107,8 +106,8 @@ private boolean shouldEnable(Object model) {
return false;
}

if(model instanceof IDiagramModelConnection) {
IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(((IDiagramModelConnection)model));
if(model instanceof ILineObject lo) {
IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(lo);
return provider != null && provider.shouldExposeFeature(IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName());
}

Expand All @@ -128,15 +127,15 @@ protected LineWidthDialog(Shell parent, int lineWidth) {
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(Messages.ConnectionLineWidthAction_1);
newShell.setText(Messages.LineWidthAction_1);
}

@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite)super.createDialogArea(parent);

fCombo = new Combo(composite, SWT.READ_ONLY);
fCombo.setItems(DiagramConnectionSection.comboLineWidthItems);
fCombo.setItems(LineWidthSection.comboLineWidthItems);
fCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fCombo.select(fLineWidth - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public class Messages extends NLS {

public static String BringToFrontAction_0;

public static String ConnectionLineWidthAction_0;

public static String ConnectionLineWidthAction_1;

public static String ConnectionRouterAction_0;

public static String ConnectionRouterAction_1;
Expand Down Expand Up @@ -83,6 +79,10 @@ public class Messages extends NLS {

public static String LineColorAction_1;

public static String LineWidthAction_0;

public static String LineWidthAction_1;

public static String LockObjectAction_0;

public static String LockObjectAction_1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ BringForwardAction_0=Bring Forward

BringToFrontAction_0=Bring To Front

ConnectionLineWidthAction_0=Line width...
ConnectionLineWidthAction_1=Connection line width

ConnectionRouterAction_0=Manual
ConnectionRouterAction_1=Shortest Path
ConnectionRouterAction_2=Manhattan
Expand Down Expand Up @@ -50,6 +47,8 @@ GenerateViewAction_0=Generate View For...

LineColorAction_0=Line colour...
LineColorAction_1=Change line colour
LineWidthAction_0=Line width...
LineWidthAction_1=Line width
LockObjectAction_0=Lock
LockObjectAction_1=Lock the component
LockObjectAction_2=Unlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ protected void setLineWidth(Graphics graphics, Rectangle bounds) {
* @param bounds The bounds of the object
*/
protected void setLineWidth(Graphics graphics, int lineWidth, Rectangle bounds) {
lineWidth = lineWidth < 1 ? 1 : lineWidth > 4 ? 4 : lineWidth;

graphics.setLineWidth(lineWidth);

final double scale = FigureUtils.getGraphicsScale(graphics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import org.eclipse.ui.PlatformUI;

import com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand;
import com.archimatetool.editor.diagram.commands.LineWidthCommand;
import com.archimatetool.editor.model.commands.FeatureCommand;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelConnection;
import com.archimatetool.model.IFeatures;
import com.archimatetool.model.ILineObject;



Expand Down Expand Up @@ -53,7 +51,6 @@ public Class<?> getAdaptableType() {
}

private Combo fComboTextPosition;
private Combo fComboLineWidth;
private Button fButtonDisplayName;

public static final String[] comboTextPositionItems = {
Expand All @@ -62,17 +59,10 @@ public Class<?> getAdaptableType() {
Messages.DiagramConnectionSection_2
};

public static final String[] comboLineWidthItems = {
Messages.DiagramConnectionSection_3,
Messages.DiagramConnectionSection_4,
Messages.DiagramConnectionSection_5
};

@Override
protected void createControls(Composite parent) {
createDisplayNameControl(parent);
createTextPositionComboControl(parent);
createLineWidthComboControl(parent);

// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
Expand All @@ -86,7 +76,6 @@ private void createTextPositionComboControl(Composite parent) {
fComboTextPosition.setItems(comboTextPositionItems);

GridData gd = new GridData(SWT.NONE, SWT.NONE, true, false);
gd.minimumWidth = ITabbedLayoutConstants.COMBO_WIDTH;
fComboTextPosition.setLayoutData(gd);

fComboTextPosition.addSelectionListener(new SelectionAdapter() {
Expand All @@ -108,36 +97,6 @@ public void widgetSelected(SelectionEvent e) {
});
}

private void createLineWidthComboControl(Composite parent) {
createLabel(parent, Messages.DiagramConnectionSection_7, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);

fComboLineWidth = new Combo(parent, SWT.READ_ONLY);
getWidgetFactory().adapt(fComboLineWidth, true, true);
fComboLineWidth.setItems(comboLineWidthItems);

GridData gd = new GridData(SWT.NONE, SWT.NONE, true, false);
gd.minimumWidth = ITabbedLayoutConstants.COMBO_WIDTH;
fComboLineWidth.setLayoutData(gd);

fComboLineWidth.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CompoundCommand result = new CompoundCommand();

for(EObject connection : getEObjects()) {
if(isAlive(connection)) {
Command cmd = new LineWidthCommand((ILineObject)connection, fComboLineWidth.getSelectionIndex() + 1);
if(cmd.canExecute()) {
result.add(cmd);
}
}
}

executeCommand(result.unwrap());
}
});
}

private void createDisplayNameControl(Composite parent) {
createLabel(parent, Messages.DiagramConnectionSection_8 + ":", ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER); //$NON-NLS-1$

Expand Down Expand Up @@ -171,9 +130,6 @@ protected void notifyChanged(Notification msg) {
if(feature == IArchimatePackage.Literals.DIAGRAM_MODEL_CONNECTION__TEXT_POSITION) {
refreshTextPositionCombo();
}
else if(feature == IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH) {
refreshLineWidthCombo();
}
else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) {
update();
}
Expand All @@ -189,7 +145,6 @@ else if(feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) {
protected void update() {
refreshNameVisibleButton();
refreshTextPositionCombo();
refreshLineWidthCombo();
}

protected void refreshTextPositionCombo() {
Expand All @@ -205,19 +160,6 @@ protected void refreshTextPositionCombo() {
fComboTextPosition.setEnabled(!isLocked(lastSelectedConnection));
}

protected void refreshLineWidthCombo() {
if(fIsExecutingCommand) {
return;
}

IDiagramModelConnection lastSelectedConnection = (IDiagramModelConnection)getFirstSelectedObject();

int lineWidth = lastSelectedConnection.getLineWidth();
fComboLineWidth.select(lineWidth - 1);

fComboLineWidth.setEnabled(!isLocked(lastSelectedConnection));
}

protected void refreshNameVisibleButton() {
if(fIsExecutingCommand) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.archimatetool.editor.diagram.commands.LineWidthCommand;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelObject;
import com.archimatetool.model.ILineObject;



Expand All @@ -36,22 +36,21 @@ public final class LineWidthSection extends AbstractECorePropertySection {
public static class Filter extends ObjectFilter {
@Override
public boolean isRequiredType(Object object) {
return object instanceof IDiagramModelObject;
return object instanceof ILineObject lo && shouldExposeFeature(lo, IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName());
}

@Override
public Class<?> getAdaptableType() {
return IDiagramModelObject.class;
return ILineObject.class;
}
}

private Combo fComboLineWidth;

private static final String[] comboLineWidthItems = {
public static final String[] comboLineWidthItems = {
Messages.LineWidthSection_1,
Messages.LineWidthSection_2,
Messages.LineWidthSection_3,
Messages.LineWidthSection_4
Messages.LineWidthSection_3
};

@Override
Expand All @@ -72,9 +71,9 @@ private void createLineWidthComboControl(Composite parent) {
fComboLineWidth.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
CompoundCommand result = new CompoundCommand();

for(EObject connection : getEObjects()) {
if(isAlive(connection)) {
Command cmd = new LineWidthCommand((IDiagramModelObject)connection, fComboLineWidth.getSelectionIndex() + 1);
for(EObject obj : getEObjects()) {
if(isAlive(obj)) {
Command cmd = new LineWidthCommand((ILineObject)obj, fComboLineWidth.getSelectionIndex() + 1);
if(cmd.canExecute()) {
result.add(cmd);
}
Expand Down Expand Up @@ -109,10 +108,10 @@ private void refreshLineWidthCombo() {
return;
}

IDiagramModelObject firstSelected = (IDiagramModelObject)getFirstSelectedObject();
ILineObject firstSelected = (ILineObject)getFirstSelectedObject();

int lineWidth = firstSelected.getLineWidth();
lineWidth = lineWidth < 1 ? 1 : lineWidth > 4 ? 4 : lineWidth;
lineWidth = lineWidth < 1 ? 1 : lineWidth > 3 ? 3 : lineWidth;

fComboLineWidth.select(lineWidth - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,8 @@ public class Messages extends NLS {

public static String DiagramConnectionSection_2;

public static String DiagramConnectionSection_3;

public static String DiagramConnectionSection_4;

public static String DiagramConnectionSection_5;

public static String DiagramConnectionSection_6;

public static String DiagramConnectionSection_7;

public static String DiagramConnectionSection_8;

public static String DiagramFigureTypeSection_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ DiagramConnectionLineStyleSection_9=Line
DiagramConnectionSection_0=Source
DiagramConnectionSection_1=Middle
DiagramConnectionSection_2=Target
DiagramConnectionSection_3=Normal
DiagramConnectionSection_4=Medium
DiagramConnectionSection_5=Heavy
DiagramConnectionSection_6=Text Position:
DiagramConnectionSection_7=Line Width:
DiagramConnectionSection_8=Show Label

DiagramFigureTypeSection_0=Figure Type
Expand Down

0 comments on commit 6e61283

Please sign in to comment.