List of usage examples for java.util Collections swap
private static void swap(Object[] arr, int i, int j)
From source file:hydrograph.ui.propertywindow.widgets.dialogs.ELTOperationClassDialog.java
private void moveRowDown(TableViewer nameValueTableViewer) { Table table = nameValueTableViewer.getTable(); int[] indexes = table.getSelectionIndices(); for (int i = indexes.length - 1; i > -1; i--) { if (indexes[i] < operationClassProperty.getNameValuePropertyList().size() - 1) { Collections.swap(operationClassProperty.getNameValuePropertyList(), indexes[i], indexes[i] + 1); nameValueTableViewer.refresh(); applyButton.setEnabled(true); }/*from ww w .j a v a 2 s . co m*/ } }
From source file:com.formkiq.core.service.workflow.WorkflowEditorServiceImpl.java
@Override public void eventIdsectionmove(final WebFlow flow, final String[] fieldid) throws IOException { FormJSON form = getCurrentFormJSON(flow); String[] fieldids = Arrays.first(fieldid).split(","); if (fieldids.length != 2 || form == null) { throw new PreconditionFailedException("bad request"); }/*from w w w .java 2s. com*/ int p0 = NumberUtils.toInt(fieldids[0], -1); int p1 = NumberUtils.toInt(fieldids[1], -1); FormJSONSection s0 = CollectionUtil.get(form.getSections(), p0, null); FormJSONSection s1 = CollectionUtil.get(form.getSections(), p1, null); if (s0 != null && s1 != null) { Collections.swap(form.getSections(), p0, p1); } else { throw new PreconditionFailedException("bad request"); } }
From source file:io.plaidapp.core.ui.FeedAdapter.java
private void expandPopularItems() { // for now just expand the first dribbble image per page which should be // the most popular according to our weighing & sorting List<Integer> expandedPositions = new ArrayList<>(); int page = -1; final int count = items.size(); for (int i = 0; i < count; i++) { PlaidItem item = getItem(i);/*w w w . jav a 2s. c om*/ if (item instanceof Shot && item.getPage() > page) { item.setColspan(columns); page = item.getPage(); expandedPositions.add(i); } else { item.setColspan(1); } } // make sure that any expanded items are at the start of a row // so that we don't leave any gaps in the grid for (int expandedPos = 0; expandedPos < expandedPositions.size(); expandedPos++) { int pos = expandedPositions.get(expandedPos); int extraSpannedSpaces = expandedPos * (columns - 1); int rowPosition = (pos + extraSpannedSpaces) % columns; if (rowPosition != 0) { int swapWith = pos + (columns - rowPosition); if (swapWith < items.size()) { Collections.swap(items, pos, swapWith); } } } }
From source file:org.deidentifier.arx.gui.view.impl.wizard.ImportWizardPageColumns.java
/** * Creates the design of this page along with the appropriate listeners. * * @param parent/*from w w w .jav a 2 s . com*/ */ public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); setControl(container); container.setLayout(new GridLayout(2, false)); /* TableViewer for the columns with a checkbox in each row */ checkboxTableViewer = SWTUtil.createTableViewerCheckbox(container, SWT.BORDER | SWT.FULL_SELECTION); checkboxTableViewer.setContentProvider(new ArrayContentProvider()); checkboxTableViewer.setCheckStateProvider(new ICheckStateProvider() { /** @return {@link ImportWizardModelColumn#isEnabled()} */ @Override public boolean isChecked(Object column) { return ((ImportWizardModelColumn) column).isEnabled(); } /** No column should be grayed out */ @Override public boolean isGrayed(Object column) { return false; } }); checkboxTableViewer.addCheckStateListener(new ICheckStateListener() { /** * Sets the enabled status for the given item * * Using {@link ImportWizardModelColumn#setEnabled(boolean)} this * method will set the enabled flag for the given column. * Furthermore it makes sure the page is marked as complete once at * least one item is selected. */ @Override public void checkStateChanged(CheckStateChangedEvent event) { ((ImportWizardModelColumn) event.getElement()).setEnabled(event.getChecked()); check(); } }); /* Actual table for {@link #checkboxTableViewer} */ table = checkboxTableViewer.getTable(); table.setHeaderVisible(true); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); table.addSelectionListener(new SelectionAdapter() { /** * Makes the buttons for column reordering (un)clickable * * This checks the current selection and will enable and/or disable * the {@link #btnUp} and {@link #btnDown} if either the first or * last item is currently selected. */ @Override public void widgetSelected(SelectionEvent e) { /* Check for first item */ if (table.getSelectionIndex() == 0) { btnUp.setEnabled(false); } else { btnUp.setEnabled(true); } /* Check for last item */ if (table.getSelectionIndex() == table.getItemCount() - 1) { btnDown.setEnabled(false); } else { btnDown.setEnabled(true); } } }); /* Empty column to make checkboxes appear in an own cell */ tableViewerColumnEnabled = new TableViewerColumn(checkboxTableViewer, SWT.NONE); tableViewerColumnEnabled.setLabelProvider(new ColumnLabelProvider() { /** Cells within this column should always be empty */ @Override public String getText(Object element) { return null; } }); /* Actual column for {@link tableViewerColumnEnabled} */ tblclmnEnabled = tableViewerColumnEnabled.getColumn(); tblclmnEnabled.setToolTipText(Resources.getMessage("ImportWizardPageColumns.11")); //$NON-NLS-1$ tblclmnEnabled.setText(Resources.getMessage("ImportWizardPageColumns.12")); //$NON-NLS-1$ tblclmnEnabled.setWidth(40); tblclmnEnabled.addSelectionListener(new ColumnEnabledSelectionListener()); /* Column containing the names */ tableViewerColumnName = new TableViewerColumn(checkboxTableViewer, SWT.NONE); tableViewerColumnName.setEditingSupport(new NameEditingSupport(checkboxTableViewer)); tableViewerColumnName.setLabelProvider(new ColumnLabelProvider() { /** * Gets name of cells from {@link ImportColumn#getAliasName()} * * This also makes sure that all column names are unique using * {@link #uniqueColumnNames()}. In case there are duplicates it * sets an error message. */ @Override public String getText(Object element) { ImportWizardModelColumn column = (ImportWizardModelColumn) element; return column.getColumn().getAliasName(); } }); /* Actual column for {@link tableViewerColumnName} */ tblclmnName = tableViewerColumnName.getColumn(); tblclmnName.setToolTipText(Resources.getMessage("ImportWizardPageColumns.13")); //$NON-NLS-1$ tblclmnName.setWidth(300); tblclmnName.setText(Resources.getMessage("ImportWizardPageColumns.14")); //$NON-NLS-1$ /* Column containing the datatypes */ tableViewerColumnDatatype = new TableViewerColumn(checkboxTableViewer, SWT.NONE); tableViewerColumnDatatypeEditingSupport = new DatatypeEditingSupport(checkboxTableViewer); tableViewerColumnDatatype.setEditingSupport(tableViewerColumnDatatypeEditingSupport); tableViewerColumnDatatype.setLabelProvider(new ColumnLabelProvider() { /** * Gets string representation for given datatype of column * * Internally it makes use of {@link ImportColumn#getDataType()}. */ @Override public String getText(Object element) { ImportWizardModelColumn column = (ImportWizardModelColumn) element; DataType<?> datatype = column.getColumn().getDataType(); return datatype.getDescription().getLabel(); } }); /* Actual column for {@link tableViewerColumnDatatype} */ tblclmnDatatype = tableViewerColumnDatatype.getColumn(); tblclmnDatatype.setToolTipText(Resources.getMessage("ImportWizardPageColumns.15")); //$NON-NLS-1$ tblclmnDatatype.setWidth(120); tblclmnDatatype.setText(Resources.getMessage("ImportWizardPageColumns.16")); //$NON-NLS-1$ /* Column containing the format of the format */ tableViewerColumnFormat = new TableViewerColumn(checkboxTableViewer, SWT.NONE); tableViewerColumnFormat.setLabelProvider(new ColumnLabelProvider() { /** * Returns format string of datatype for column * * This retrieves the used format string of the chosen datatype for * each column. * * @note In case of simple datatypes without a format specifier an * empty string is returned. * * @param element * Column in question */ @Override public String getText(Object element) { DataType<?> column = ((ImportWizardModelColumn) element).getColumn().getDataType(); if (column instanceof DataTypeWithFormat) { return ((DataTypeWithFormat) column).getFormat(); } return ""; //$NON-NLS-1$ } }); /* Actual column for {@link tableViewerColumnFormat} */ tblclmnFormat = tableViewerColumnFormat.getColumn(); tblclmnFormat.setWidth(120); tblclmnFormat.setToolTipText(Resources.getMessage("ImportWizardPageColumns.18")); //$NON-NLS-1$ tblclmnFormat.setWidth(100); tblclmnFormat.setText(Resources.getMessage("ImportWizardPageColumns.19")); //$NON-NLS-1$ /* Buttons to move column up */ btnUp = new Button(container, SWT.NONE); btnUp.setText(Resources.getMessage("ImportWizardPageColumns.20")); //$NON-NLS-1$ btnUp.setImage(wizardImport.getController().getResources().getManagedImage("arrow_up.png")); //$NON-NLS-1$ btnUp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); btnUp.setEnabled(false); btnUp.addSelectionListener(new SelectionAdapter() { /** * Swaps the current element with the one above * * This makes also sure that the button is disabled once the top is * reached by notifying the appropriate selection listener. */ @Override public void widgetSelected(SelectionEvent e) { int current = table.getSelectionIndex(); if (current > 0) { List<ImportWizardModelColumn> columns = wizardImport.getData().getWizardColumns(); Collections.swap(columns, current, current - 1); checkboxTableViewer.setInput(columns); table.notifyListeners(SWT.Selection, null); } } }); /* Buttons to move column down */ btnDown = new Button(container, SWT.NONE); btnDown.setText(Resources.getMessage("ImportWizardPageColumns.22")); //$NON-NLS-1$ btnDown.setImage(wizardImport.getController().getResources().getManagedImage("arrow_down.png")); //$NON-NLS-1$ btnDown.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); btnDown.setEnabled(false); btnDown.addSelectionListener(new SelectionAdapter() { /** * Swaps the current element with the one below * * This makes also sure that the button is disabled once the bottom * is reached by notifying the appropriate selection listener. */ @Override public void widgetSelected(SelectionEvent e) { int current = table.getSelectionIndex(); if (current < table.getItemCount() - 1) { List<ImportWizardModelColumn> columns = wizardImport.getData().getWizardColumns(); Collections.swap(columns, current, current + 1); checkboxTableViewer.setInput(columns); table.notifyListeners(SWT.Selection, null); } } }); btnCleansing = new Button(container, SWT.CHECK); btnCleansing.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create()); btnCleansing.setText(Resources.getMessage("ImportWizardPageColumns.24")); //$NON-NLS-1$ btnCleansing.setToolTipText(Resources.getMessage("ImportWizardPageColumns.25")); //$NON-NLS-1$ btnCleansing.setEnabled(true); btnCleansing.setSelection(wizardImport.getData().isPerformCleansing()); btnCleansing.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { wizardImport.getData().setPerformCleansing(btnCleansing.getSelection()); } }); /* Wait for at least one column to be enabled */ setPageComplete(false); }
From source file:hydrograph.ui.propertywindow.widgets.dialogs.lookup.LookupMapDialog.java
private void moveRowDown() { Table table = mappingTableViewer.getTable(); setValueForCellEditor();//from www . j a v a2 s. c om int[] indexes = table.getSelectionIndices(); for (int i = indexes.length - 1; i > -1; i--) { if (indexes[i] < mappingTableItemList.size() - 1) { Collections.swap((List<LookupMapProperty>) mappingTableItemList, indexes[i], indexes[i] + 1); mappingTableViewer.refresh(); } } refreshButtonStatus(); }
From source file:com.nextep.datadesigner.dbgm.gui.IndexEditorGUI.java
private void indexColumnUp(IIndex index, IBasicColumn column) { final IReference columnRef = column.getReference(); final List<IReference> colRefs = index.getIndexedColumnsRef(); int colIndex = colRefs.indexOf(columnRef); if (colIndex > 0) { final IBasicColumn swappedCol = index.getColumns().get(colIndex - 1); Collections.swap(colRefs, colIndex, colIndex - 1); index.notifyListeners(ChangeEvent.MODEL_CHANGED, column); column.notifyListeners(ChangeEvent.MODEL_CHANGED, null); swappedCol.notifyListeners(ChangeEvent.MODEL_CHANGED, null); }//w w w . ja v a 2 s . co m }
From source file:io.plaidapp.ui.FeedAdapter.java
private void expandPopularItems() { // for now just expand the first dribbble image per page which should be // the most popular according to our weighing & sorting List<Integer> expandedPositions = new ArrayList<>(); int page = -1; final int count = items.size(); for (int i = 0; i < count; i++) { PlaidItem item = getItem(i);/*from w w w .j a va 2 s . c o m*/ if (item instanceof Shot && item.page > page) { item.colspan = columns; page = item.page; expandedPositions.add(i); } else { item.colspan = 1; } } // make sure that any expanded items are at the start of a row // so that we don't leave any gaps in the grid for (int expandedPos = 0; expandedPos < expandedPositions.size(); expandedPos++) { int pos = expandedPositions.get(expandedPos); int extraSpannedSpaces = expandedPos * (columns - 1); int rowPosition = (pos + extraSpannedSpaces) % columns; if (rowPosition != 0) { int swapWith = pos + (columns - rowPosition); if (swapWith < items.size()) { Collections.swap(items, pos, swapWith); } } } }
From source file:hydrograph.ui.propertywindow.widgets.dialogs.lookup.LookupMapDialog.java
private void moveRowUp() { Table table = mappingTableViewer.getTable(); setValueForCellEditor();/* w w w.jav a 2 s . c o m*/ int[] indexes = table.getSelectionIndices(); for (int index : indexes) { if (index > 0) { Collections.swap((List<LookupMapProperty>) mappingTableItemList, index, index - 1); mappingTableViewer.refresh(); } } refreshButtonStatus(); }
From source file:com.nextep.datadesigner.dbgm.gui.IndexEditorGUI.java
private void indexColumnDown(IIndex index, IBasicColumn c) { final IReference columnRef = c.getReference(); final List<IReference> colRef = index.getIndexedColumnsRef(); int colIndex = colRef.indexOf(columnRef); if (colIndex < colRef.size() - 1) { final IBasicColumn swappedCol = index.getColumns().get(colIndex + 1); Collections.swap(colRef, colIndex, colIndex + 1); index.notifyListeners(ChangeEvent.MODEL_CHANGED, c); c.notifyListeners(ChangeEvent.MODEL_CHANGED, null); swappedCol.notifyListeners(ChangeEvent.MODEL_CHANGED, null); }/*from ww w . j a v a 2s . co m*/ }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java
@Override public void onItemMoved(int fromPosition, int toPosition) { Collections.swap(mPendingActions, fromPosition, toPosition); mAdapter.notifyItemMoved(fromPosition, toPosition); }