/** * Constructor * @param selection * @param sourceName * @param dataManager */ public TableEditableElementImpl(Set<Long> selection, String sourceName, DataManager dataManager) { super(sourceName, dataManager); this.selectedGeometries = new LongUnion(selection); }
/** * Copy constructor with a generic collection * @param externalCollection */ public LongUnion(Collection<Long> externalCollection) { this(); if(externalCollection instanceof LongUnion) { copyExternalLongUnion((LongUnion)externalCollection); } else { for(Long value : externalCollection) { internalAdd(value); } } }
@Override public boolean remove(Object o) { Long value = (Long) o; return internalRemove(value); }
private void writeSelection(OutputStream out) throws IOException { ObjectOutputStream selectionOut = new ObjectOutputStream(out); //Do not save byte consuming selection LongUnion mergedSelection; Set<Long> selection = tableEditableElement.getSelection(); if(selection instanceof LongUnion) { mergedSelection = (LongUnion) selection; } else { mergedSelection = new LongUnion(selection); } if(mergedSelection.getValueRanges().size()>MAX_SELECTION_SERIALISATION_SIZE) { selectionOut.writeObject(new IntegerUnion()); } else { selectionOut.writeObject(mergedSelection); } selectionOut.flush(); selectionOut.close(); }
@Override protected void done() { try { if (controlDown) { LongUnion newSel = new LongUnion(activeLayer.getSelection()); for (long el : get()) { if (!newSel.remove(el)) { newSel.add(el); } } activeLayer.setSelection(newSel); } else { activeLayer.setSelection(get()); } if (activeLayer.getSelection().isEmpty()) { automaton.transition(Code.NO_SELECTION); } else { automaton.transition(Code.SELECTION); } } catch (Exception ex) { try { automaton.transition(Code.NO_SELECTION); } catch (TransitionException | FinishedAutomatonException e) { // Ignore } automaton.logger.error(ex.getLocalizedMessage(), ex); } } }
@Override public boolean addAll(Collection<? extends Long> clctn) { boolean isAllAdded=true; for (Iterator<? extends Long> it = clctn.iterator(); it.hasNext();) { Long value = it.next(); if(!add(value)) { isAllAdded = false; } } return isAllAdded; }
@Override protected Object doInBackground() throws SQLException { try(Connection connection = dataSource.getConnection()) { boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); int columnId = JDBCUtilities.getIntegerPrimaryKey(connection, tableName); if(columnId > 0) { String pkColumnName = JDBCUtilities.getFieldName(connection.getMetaData(), tableName, columnId); // A deletion batch is an ordered set of pk values to remove (a complete serial of integer without holes) List<Long> deletionBatch = rowPkToDelete.getValueRanges(); ProgressMonitor pmBatch = getProgressMonitor().startTask(deletionBatch.size() / 2); try(PreparedStatement st = connection.prepareStatement( String.format("DELETE FROM %s WHERE %s >= ? AND %s <= ?", TableLocation.parse(tableName).toString(isH2),pkColumnName, pkColumnName))) { for (int idDelBatch = 0; idDelBatch < deletionBatch.size() - 1; idDelBatch += 2) { long startBatch = deletionBatch.get(idDelBatch); long endBatch = deletionBatch.get(idDelBatch + 1); st.setLong(1, startBatch); st.setLong(2, endBatch); st.execute(); pmBatch.endTask(); } } } } return null; }
/** * Creator with an initial value * @param externalArray Array of int */ public LongUnion(long[] externalArray) { this(); for(Long val : externalArray) { internalAdd(val); } } /**
@Override public boolean addAll(Collection<? extends Long> clctn) { boolean isAllAdded=true; for (Iterator<? extends Long> it = clctn.iterator(); it.hasNext();) { Long value = it.next(); if(!add(value)) { isAllAdded = false; } } return isAllAdded; }
/** * Creator with an initial value * @param externalArray Array of int */ public LongUnion(long[] externalArray) { this(); for(Long val : externalArray) { internalAdd(val); } } /**
/** * Constructor * @param sourceName * @param dataManager */ public TableEditableElementImpl(String sourceName, DataManager dataManager) { super(sourceName, dataManager); this.selectedGeometries = new LongUnion(); }
/** * Copy constructor with a generic collection * @param externalCollection */ public LongUnion(Collection<Long> externalCollection) { this(); if(externalCollection instanceof LongUnion) { copyExternalLongUnion((LongUnion)externalCollection); } else { for(Long value : externalCollection) { internalAdd(value); } } }
@Override public boolean add(Long value) { return internalAdd(value); }
@Override public boolean remove(Object o) { Long value = (Long) o; return internalRemove(value); }
@Override public void setSelection(Set<Long> newSelection) { LongUnion oldSelection = selection; selection = new LongUnion(newSelection); propertyChangeSupport.firePropertyChange(PROP_SELECTION, oldSelection, selection); } }
@Override public boolean add(Long value) { return internalAdd(value); }
@Override public void setSelection(Set<Long> selection) { LOGGER.debug("Editable selection change"); Set<Long> oldSelection = this.selectedGeometries; this.selectedGeometries = new LongUnion(selection); propertyChangeSupport.firePropertyChange(PROP_SELECTION, oldSelection, getSelection()); }
/** * Copy constructor with a generic collection * @param valueIterator Value to insert in this set */ public LongUnion(Iterator<Long> valueIterator) { this(); while(valueIterator.hasNext()) { internalAdd(valueIterator.next()); } }
private LongUnion readSelection(InputStream in) { try { ObjectInputStream selectionIn = new ObjectInputStream(in); return (LongUnion)selectionIn.readObject(); } catch (ClassNotFoundException | IOException ex) { LOGGER.error(I18N.tr("Selection deserialisation failed"),ex); } return new LongUnion(); } @Override
/** * Copy constructor with a generic collection * @param valueIterator Value to insert in this set */ public LongUnion(Iterator<Long> valueIterator) { this(); while(valueIterator.hasNext()) { internalAdd(valueIterator.next()); } }