helper method to switch the profiles

@param newSelection
@return true if the new selection was the current profile
10846
protected boolean switchProfiles(IProfile newSelection) {
        if (newSelection == null) {
            return false;
        }
        if (mCurrentProfile == newSelection) {
            return true;
        }

        if (mAlternativeProfileHeaderSwitching) {
            int prevSelection = -1;
            if (mProfileFirst == newSelection) {
                prevSelection = 1;
            } else if (mProfileSecond == newSelection) {
                prevSelection = 2;
            } else if (mProfileThird == newSelection) {
                prevSelection = 3;
            }

            IProfile tmp = mCurrentProfile;
            mCurrentProfile = newSelection;

            if (prevSelection == 1) {
                mProfileFirst = tmp;
            } else if (prevSelection == 2) {
                mProfileSecond = tmp;
            } else if (prevSelection == 3) {
                mProfileThird = tmp;
            }
        } else {
            if (mProfiles != null) {
                ArrayList<IProfile> previousActiveProfiles = new ArrayList<>(Arrays.asList(mCurrentProfile, mProfileFirst, mProfileSecond, mProfileThird));

                if (previousActiveProfiles.contains(newSelection)) {
                    int position = -1;

                    for (int i = 0; i < 4; i++) {
                        if (previousActiveProfiles.get(i) == newSelection) {
                            position = i;
                            break;
                        }
                    }

                    if (position != -1) {
                        previousActiveProfiles.remove(position);
                        previousActiveProfiles.add(0, newSelection);

                        mCurrentProfile = previousActiveProfiles.get(0);
                        mProfileFirst = previousActiveProfiles.get(1);
                        mProfileSecond = previousActiveProfiles.get(2);
                        mProfileThird = previousActiveProfiles.get(3);
                    }
                } else {
                    mProfileThird = mProfileSecond;
                    mProfileSecond = mProfileFirst;
                    mProfileFirst = mCurrentProfile;
                    mCurrentProfile = newSelection;
                }
            }
        }

        //if we only show the small profile images we have to make sure the first (would be the current selected) profile is also shown
        if (mOnlySmallProfileImagesVisible) {
            mProfileThird = mProfileSecond;
            mProfileSecond = mProfileFirst;
            mProfileFirst = mCurrentProfile;
            //mCurrentProfile = mProfileThird;
        }

        buildProfiles();

        return false;
    }
594165
@Handler(priority = 1000)
    public void onProtocolSwitchAccepted(
            ProtocolSwitchAccepted event, IOSubchannel channel) {
        event.requestEvent().associated(Selection.class)
            .ifPresent(
                selection -> channel.setAssociated(Selection.class, selection));
    }
551901
public <T extends Type> T selectCandidate(T candidate, T next, T actual, Environment environment) {
		// Found a viable candidate
		boolean left = subtypeOperator.isSubtype(candidate, next, environment);
		boolean right = subtypeOperator.isSubtype(next, candidate, environment);
		if (left && !right) {
			// Yes, is better than current candidate
			return next;
		} else if (right && !left) {
			return candidate;
		}
		// Unable to distinguish options based on subtyping alone
		left = isDerivation(next, actual);
		right = isDerivation(candidate, actual);
		if (left && !right) {
			// Yes, is better than current candidate
			return next;
		} else if (right && !left) {
			return candidate;
		} else {
			return null;
		}

	}
158312
private void handleSelectionView(IProfile profile, boolean on) {
        if (on) {
            if (Build.VERSION.SDK_INT >= 23) {
                mAccountHeaderContainer.setForeground(AppCompatResources.getDrawable(mAccountHeaderContainer.getContext(), mAccountHeaderTextSectionBackgroundResource));
            } else {
                // todo foreground thing?
            }
            mAccountHeaderContainer.setOnClickListener(onSelectionClickListener);
            mAccountHeaderContainer.setTag(R.id.material_drawer_profile_header, profile);
        } else {
            if (Build.VERSION.SDK_INT >= 23) {
                mAccountHeaderContainer.setForeground(null);
            } else {
                // TODO foreground reset
            }
            mAccountHeaderContainer.setOnClickListener(null);
        }
    }
569481
public boolean selectionChanged(Object source, int iStartRow, int iEndRow, int iSelectType)
    {
        boolean bChanged = super.selectionChanged(source, iStartRow, iEndRow, iSelectType);
        if (bChanged)
        { // Notify all the listSelectionListeners
            this.fireMySelectionChanged(new MyListSelectionEvent(source, this, m_iSelectedRow, iSelectType));
        }
        return bChanged;
    }
988849
@SuppressWarnings("checkstyle:npathcomplexity")
	public boolean selectSpecificSRE(ISREInstall sre) {
		ISREInstall theSRE = sre;
		if (theSRE == null) {
			theSRE = SARLRuntime.getDefaultSREInstall();
		}
		if (theSRE != null) {
			boolean changed = false;
			final boolean oldNotify = this.notify;
			try {
				this.notify = false;
				if (isSystemWideDefaultSRE()) {
					doSpecificSREButtonClick();
					changed = true;
				}
				final ISREInstall oldSRE = getSelectedSRE();
				if (oldSRE != theSRE) {
					final int index = indexOf(theSRE);
					if (index >= 0) {
						this.runtimeEnvironmentCombo.select(index);
						changed = true;
					}
				}
				if (!this.runtimeEnvironments.isEmpty()) {
					int selection = this.runtimeEnvironmentCombo.getSelectionIndex();
					if (selection < 0 || selection >= this.runtimeEnvironments.size()) {
						// Ensure that there is a selected element
						selection = indexOf(theSRE);
						this.runtimeEnvironmentCombo.select((selection < 0) ? 0 : selection);
						changed = true;
					}
				}
			} finally {
				this.notify = oldNotify;
			}
			if (changed) {
				firePropertyChange();
				return true;
			}
		}
		return false;
	}
1210493
private Set<String> getNewSelections(final Request request) {

		// Check for any selections on the request
		String[] paramValue = request.getParameterValues(getId());
		String[] selectedRowIds = removeEmptyStrings(paramValue);
		if (selectedRowIds == null || selectedRowIds.length == 0) {
			return Collections.EMPTY_SET;
		}

		Set<String> newSelectionIds = new HashSet<>();

		boolean singleSelect = getSelectMode() == SelectMode.SINGLE;

		int offset = getItemIdPrefix().length();
		for (String selectedRowId : selectedRowIds) {
			if (selectedRowId.length() <= offset) {
				LOG.warn("Selected row id [" + selectedRowId + "] does not have a valid prefix and will be ignored.");
				continue;
			}
			String itemId = selectedRowId.substring(offset);
			if (isValidTreeItem(itemId)) {
				newSelectionIds.add(itemId);
				if (singleSelect) {
					break;
				}
			} else {
				LOG.warn("Selected row id [" + itemId + "] is not valid and will be ignored.");
			}
		}

		return newSelectionIds;
	}
850551
private StateUpdater createSelection(Viewer viewer, Cursor cursor, SelectorModel model, StateUpdater reset)
    {
        return (extrp, current) ->
        {
            computeSelection(viewer, cursor, model);

            if (model.getSelectionClick() != cursor.getClick())
            {
                collidable.setEnabled(true);
                final Rectangle sel = model.getSelectionArea();
                final Area done = Geom.createArea(sel.getX(), sel.getY(), sel.getWidthReal(), sel.getHeightReal());
                for (final SelectorListener listener : listeners)
                {
                    listener.notifySelectionDone(done);
                }
                sel.set(-1, -1, 0, 0);
                model.setSelecting(false);

                return reset;
            }
            return current;
        };
    }
225784
public void changeSelectInterests()
    {
        switch (state)
        {
            case READY_TO_WRITE: // set the OP_WRITE interest
                state = State.WRITING;
                break;

            case READY_TO_READ_FRAME_SIZE:
                state = State.READING_FRAME_SIZE;
                break;

            case READY_TO_READ_FRAME:
                state = State.READING_FRAME;
                break;

            case AWAITING_CLOSE:
                close();
                selectionKey.cancel();
                break;

            default:
                logger.error("changeSelectInterest was called, but state is invalid (" + state + ")");
        }
    }
896162
def select_profile(self, obresult):
        """"""

        logger = logging.getLogger(__name__)
        logger.debug('calling default profile selector')
        # check configuration
        insconf = obresult.configuration
        if insconf != 'default':
            key = insconf
            date_obs = None
            keyname = 'uuid'
        else:
            # get first possible image
            ref = obresult.get_sample_frame()
            if ref is None:
                key = obresult.instrument
                date_obs = None
                keyname = 'name'
            else:
                extr = self.datamodel.extractor_map['fits']

                date_obs = extr.extract('observation_date', ref)
                key = extr.extract('insconf', ref)
                if key is not None:
                    keyname = 'uuid'
                else:
                    key = extr.extract('instrument', ref)
                    keyname = 'name'

        return key, date_obs, keyname
1099704
def on_lstClassifications_itemSelectionChanged(self):
        
        self.clear_further_steps()
        classification = self.selected_classification()
        # Exit if no selection
        if not classification:
            return
        # Set description label
        self.lblDescribeClassification.setText(classification["description"])
        # Enable the next button
        self.parent.pbnNext.setEnabled(True)
1334741
@UiHandler("navTree")
  final void menuItemSelected(final SelectionEvent<TreeItem> pselectionEvent) {
    if (selectedItem != null && !selectedItem.equals(pselectionEvent.getSelectedItem())) {
      // workaround, revert selection, it's triggered by the selected page
      pselectionEvent.getSelectedItem().setSelected(false);
      selectedItem.setSelected(true);
    }
  }
109957
def on_lstUnits_itemSelectionChanged(self):
        
        self.clear_further_steps()
        # Set widgets
        unit = self.selected_unit()
        # Exit if no selection
        if not unit:
            return
        self.lblDescribeUnit.setText(unit['description'])
        # Enable the next button
        self.parent.pbnNext.setEnabled(True)
788560
@Override
    public void selectionChanged(IAction action, ISelection selection) {

        bugInstance = null;
        // TODO learn to deal with ALL elements
        IMarker markerFromSelection = MarkerUtil.getMarkerFromSingleSelection(selection);
        marker = markerFromSelection;

        if (marker == null) {
            // No marker selected.
            return;
        }
        if (DEBUG) {
            System.out.println("Found a marker!");
        }

        bugInstance = MarkerUtil.findBugInstanceForMarker(marker);
        if (bugInstance != null) {
            if (DEBUG) {
                System.out.println("Found BugInstance for SpotBugs warning marker!");
            }
        }
    }
825191
void toggleSelectOU() {

        boolean create = m_fieldCreateOU.getValue().booleanValue();

        m_fieldSelectOU.setEnabled(!create);
        m_fieldSelectParentOU.setEnabled(create);
        m_fieldSelectOU.select("/");
    }
451534
public void switchDrawerContent(@NonNull OnDrawerItemClickListener onDrawerItemClickListener, OnDrawerItemLongClickListener onDrawerItemLongClickListener, @NonNull List<IDrawerItem> drawerItems, int drawerSelection) {
        //just allow a single switched drawer
        if (!switchedDrawerContent()) {
            //save out previous values
            originalOnDrawerItemClickListener = getOnDrawerItemClickListener();
            originalOnDrawerItemLongClickListener = getOnDrawerItemLongClickListener();
            originalDrawerState = getAdapter().saveInstanceState(new Bundle());
            mDrawerBuilder.mExpandableExtension.collapse(false);
            originalDrawerItems = getDrawerItems();
        }

        //set the new items
        setOnDrawerItemClickListener(onDrawerItemClickListener);
        setOnDrawerItemLongClickListener(onDrawerItemLongClickListener);
        setItems(drawerItems, true);
        setSelectionAtPosition(drawerSelection, false);

        if (!mDrawerBuilder.mKeepStickyItemsVisible) {
            //hide stickyFooter and it's shadow
            if (getStickyFooter() != null) {
                getStickyFooter().setVisibility(View.GONE);
            }
            if (getStickyFooterShadow() != null) {
                getStickyFooterShadow().setVisibility(View.GONE);
            }
        }
    }
799024
public int fieldChanged(boolean bDisplayOption, int iMoveMode)
    {
        if (m_gridScreen != null)
            m_gridScreen.reSelectRecords();
        if (m_sPopupBox != null)
            m_sPopupBox.reSelectRecords();
        return DBConstants.NORMAL_RETURN;
    }