+ if (selected == null) {
+ ok = false;
+ } else if (selected.isCode()) {// TODO : instead of disabling the button, we should filter the content.
+ ok = false;
+ } else {
+ lenghtAdjustable = ((selected.getType() == Type.INLINE)
+ && (selected.isVariable() || selected.isModifiable()));
+
+ if (!hasInsertPosition()) {
+ // We are inserting to a fully connected variable length component
+ // only allow insertion within the component
+ startButton.setEnabled(false);
+ middleButton.setEnabled(false);
+ endButton.setEnabled(false);
+ updateInsertPosition(PositionType.PREVIOUS);
+ } else if (insertAdjustable) {
+ switch (selected.getType()) {
+ case END:
+ startButton.setEnabled(false);
+ middleButton.setEnabled(false);
+ endButton.setEnabled(true);
+ updateInsertPosition(PositionType.NEXT);
+ break;
+ case INLINE:
+ if (!selected.isVariable()) {
+ startButton.setEnabled(true);
+ middleButton.setEnabled(true);
+ endButton.setEnabled(true);
+ } else {
+ startButton.setEnabled(false);
+ middleButton.setEnabled(false);
+ endButton.setEnabled(true);
+ updateInsertPosition(PositionType.NEXT);
+ }
+ break;
+ case NOZZLE:
+ startButton.setEnabled(false);
+ middleButton.setEnabled(false);
+ endButton.setEnabled(true);
+ updateInsertPosition(PositionType.NEXT);
+ break;
+ case TURN:
+ startButton.setEnabled(false);
+ middleButton.setEnabled(true);
+ endButton.setEnabled(true);
+ if (insertPosition == PositionType.PREVIOUS)
+ updateInsertPosition(PositionType.NEXT);
+ break;
+ case EQUIPMENT:
+ throw new RuntimeException("Expected component, got equipment " + selected);
+ }
+ } else if (lenghtAdjustable) {
+ if (component instanceof InlineComponent) {
+ startButton.setEnabled(true);
+ middleButton.setEnabled(true);
+ endButton.setEnabled(true);
+ } else if (component instanceof TurnComponent) {
+ startButton.setEnabled(false);
+ middleButton.setEnabled(true);
+ endButton.setEnabled(true);
+ if (insertPosition == PositionType.PREVIOUS)
+ updateInsertPosition(PositionType.NEXT);
+ } else if (component instanceof EndComponent || component instanceof Nozzle) {
+ startButton.setEnabled(false);
+ middleButton.setEnabled(false);
+ endButton.setEnabled(true);
+ updateInsertPosition(PositionType.NEXT);
+ }
+ } else {
+ startButton.setEnabled(false);
+ middleButton.setEnabled(false);
+ endButton.setEnabled(true);
+ }
+ if (selected.isVariable() || selected.isModifiable()) {
+ if (selected.getType() == Type.INLINE) {
+ filterAllowed.add(PositionType.NEXT);
+ filterAllowed.add(PositionType.PREVIOUS);
+ if (inlineSplit && selected.isVariable()) {
+ lengthText.setEnabled(false);
+ angleText.setEnabled(false);
+ rotationAngleText.setEnabled(selected.isRotated());
+ ok = false;
+ if (msg == null) msg = "Cannot split a straight pipe with a straight pipe";
+ } else {
+ lengthText.setEnabled(true);
+ angleText.setEnabled(false);
+ rotationAngleText.setEnabled(selected.isRotated());
+ if (length == null || length <= 0.0) {
+ ok = false;
+ if (msg == null) msg = "Please provide a valid length";
+ }
+ }
+ } else if (selected.getType() == Type.TURN) {
+ filterAllowed.add(PositionType.NEXT);
+ filterAllowed.add(PositionType.PREVIOUS);