public void expandBlock(Block block, boolean state) { if (block.isExpanded() == state || !block.canExpand() || block.getSize() == 1) return; Point range = getBlockSelectionRange(block); int delta = 0; m_FoldingText.m_Text.setSelection(range); if (state) { // Expanding m_FoldingText.m_Text.insert(block.getAll()); delta = block.getSize() - 1; } else { m_FoldingText.m_Text.insert(block.getFirst()); delta = 1 - block.getSize(); } // Set the selection back to the top of the range (it defaults to // the bottom) // so we see the top of the newly expanded block if it's long m_FoldingText.m_Text.setSelection(range.x); // Update the remaining block position info int size = getNumberBlocks(); for (int b = block.getIndex() + 1; b < size; b++) { Block update = getBlock(b); update.setStart(update.getStart() + delta); } block.setExpand(state); }
public void setValueAt(Object aValue, int row, int col) { int current = applyInsertModeForCursor(block.getIndex()); /**/ if (row != current) { Err.error("Should be updating the current row, " + current + " not " + row + " for " + block); // block.setIndex( true, row); } /**/ TableIdEnum id = IdEnum.newTable(getTableControl(), row, col, getColumnClass(col), null); TableSignatures.setText(id, aValue); }
/** Expand/contract all blocks currently on screen */ public void expandPage(boolean state) { // Get all the information about which part of the text window is // visible int topLine = m_Text.getTopIndex(); int lineHeight = m_Text.getLineHeight(); int visibleLines = m_Text.getClientArea().height / lineHeight; int lastLine = Math.min(m_Text.getLineCount(), m_Text.getTopIndex() + visibleLines); boolean atBottom = (lastLine == m_Text.getLineCount()); // Start with the first block that starts at topLine or includes // topLine. Block topBlock = m_FoldingDoc.getBlockByLineNumber(topLine); Block bottomBlock = m_FoldingDoc.getBlockByLineNumber(lastLine); if (topBlock == null) return; // Stop redrawing while we expand/collapse everything then turn it back // on setRedraw(false); // If the lastLine is after the bottom block, use the last block in the // document if (bottomBlock == null) bottomBlock = m_FoldingDoc.getBlock(m_FoldingDoc.getNumberBlocks() - 1); int topIndex = topBlock.getIndex(); int bottomIndex = bottomBlock.getIndex(); for (int i = topIndex; i <= bottomIndex; i++) { Block block = m_FoldingDoc.getBlock(i); m_FoldingDoc.expandBlock(block, state); } // If the selection was set to the bottom before we expanded make sure // it stays there after the expansion. if (state && atBottom) scrollBottom(); // Redraw everything setRedraw(true); }
/** * Returns the character positions for the start and end of a block -- so we can use these to * set the selection to the block */ public Point getBlockSelectionRange(Block block) { int start = 0; for (int b = 0; b < block.getIndex(); b++) { int chars = ((Block) m_TextBlocks.get(b)).getVisibleCharCount(); start += chars; } int end = start + block.getVisibleCharCount(); return new Point(start, end); }
private int applyInsertModeForAllOtherRows(int index) { int result = index; /**/ if (block == oper.getCurrentBlock() && (oper.getState(block).isNew() /* && !oper.getState( block).isPrior()*/)) { // Not using JTable anymore, and this -1 was not helping SdzDsgnr - so decided // to start using ComponentTableView instead int cursor = block.getIndex(); // - 1; if (index > cursor) { result--; } } /**/ return result; }
protected void paintIcons(PaintEvent e) { // Check if we've turned off redraws if (m_DrawingDisabled) return; GC gc = e.gc; Rectangle client = m_IconBar.getClientArea(); // Make sure the text control is properly initialized if (m_Text.getLineHeight() == 0) return; // Get all the information about which part of the text window is // visible int topLine = m_Text.getTopIndex(); int lineHeight = m_Text.getLineHeight(); int visibleLines = m_Text.getClientArea().height / lineHeight; int lastLine = Math.min(m_Text.getLineCount(), m_Text.getTopIndex() + visibleLines); // Start with the first block that starts at topLine or includes // topLine. Block topBlock = m_FoldingDoc.getBlockByLineNumber(topLine); int blockCount = m_FoldingDoc.getNumberBlocks(); if (topBlock == null) return; int blockIndex = topBlock.getIndex(); int outerSize = 9; int innerSize = 6; int offset = (outerSize - innerSize) / 2 + 1; Color gray = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_GRAY); Color black = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_BLACK); // Go through each block in turn until we're off the bottom of the // screen // or at the end of the list of blocks drawing icons while (blockIndex != -1 && blockIndex < blockCount) { Block block = m_FoldingDoc.getBlock(blockIndex); int line = block.getStart(); // Once we drop off the bottom of the screen we're done if (line >= lastLine) break; int pos = line - topLine; int y = pos * lineHeight + (lineHeight / 2) - (outerSize / 2) - 1; int x = 1; boolean expanded = block.isExpanded(); if (block.canExpand()) { gc.drawRectangle(x, y, x + outerSize, x + outerSize); // Start with a - sign int y1 = y + 1 + (outerSize / 2); gc.drawLine(x + offset, y1, x + offset + innerSize, y1); if (!expanded) { // If not expanded turn the - into a + int x1 = x + 1 + (outerSize / 2); gc.drawLine(x1, y + offset, x1, y + offset + innerSize); } else { // If expanded draw a line to show what is in the expanded // area gc.setForeground(gray); int x1 = x + 1 + (outerSize / 2); int yTop = y + outerSize + 2; int yBottom = y + ((block.getSize() - 1) * lineHeight) + (outerSize / 2); gc.drawLine(x1, yTop, x1, yBottom); gc.drawLine(x1, yBottom, client.width - 1, yBottom); gc.setForeground(black); } } blockIndex++; } }
/** * set param is hardly ever being used, which means things like will be setting the current row * visibly current when in fact it already is visibly current. No big deal! */ public void setDisplay(OperationEnum currentOperation, int row, String reason) { StateEnum currentState = oper.getState(block); Block currentBlock = oper.getCurrentBlock(); // int idxCurrentRow = block.getCursorPosition() - 1; int idxCurrentRow = block.getIndex(); if (currentState.isNew() && currentState.isPrior()) { idxCurrentRow--; } /**/ if (false /*SdzNote.SET_DISPLAY_ON_TABLE.isVisible()*/) { times++; Err.pr(""); Err.pr("Inside setDisplay for <" + block + "> times: " + times); Err.pr("\tCurrent block: " + currentBlock); Err.pr("\tblock that has table: " + block); Err.pr("\tcurrent operation: " + currentOperation); Err.pr("\tcurrent state: " + currentState); Err.pr("\trow to change to: " + idxCurrentRow); if (times == 39) { Err.debug(); } } /**/ if (currentOperation == OperationEnum.REMOVE // && currentState.isNew() // && !block.isChildOf( currentBlock) ) { usersModel.fireTableRowsDeleted(idxCurrentRow, idxCurrentRow); // usersModel.fireRowChangedTo( idxCurrentRow-1); } /* else if(currentOperation == OperationEnum.REMOVE && currentState.isNavigating() && !block.isChildOf( currentBlock)) { // w/out this, in case where deleted first row, // would not have become selected again usersModel.fireRowChangedTo( idxCurrentRow); } */ else if (currentOperation == OperationEnum.EXECUTE_QUERY) { usersModel.fireTableDataChanged( "setDisplay because of " + currentOperation + ", because " + reason); // No evidence yet that need this // usersModel.fireRowChangedTo( idxCurrentRow); } if (currentState.isNew() && (currentOperation == OperationEnum.PREVIOUS || currentOperation == OperationEnum.NEXT)) { usersModel.fireRowChangedTo(idxCurrentRow); } /* else if((currentOperation == OperationEnum.INSERT || currentOperation == OperationEnum.INSERT_PRIOR) && block == currentBlock) { usersModel.fireRowChangedTo( idxCurrentRow); Err.pr( "blankoutDisplay, have changed row to " + idxCurrentRow); } */ else if (currentOperation == OperationEnum.REFRESH) { Err.pr(/*SdzNote.SET_DISPLAY_ON_TABLE*/ false, "@@ setDisplay for op " + currentOperation); usersModel.fireTableDataChanged( row, row, "setDisplay for op " + currentOperation + " because " + reason); } else { Err.pr(SdzNote.SET_DISPLAY_ON_TABLE, "@@ setDisplay, default as op was " + currentOperation); usersModel.fireRowChangedTo(idxCurrentRow); } }
/** * Not part of the table model (so doesn't get called when the table is painting). Has proven to * be a good place to set the table up just prior to painting. */ public void blankoutDisplay(OperationEnum currentOperation, int row, String reason) { int idxCurrentRow = block.getIndex(); // OperationEnum currentOperation = oper.getCurrentOperation(); StateEnum currentState = oper.getState(block); Block currentBlock = oper.getCurrentBlock(); if (false /*SdzNote.SET_DISPLAY_ON_TABLE.isVisible()*/) { times++; Err.pr(""); Err.pr("Inside blankoutDisplay for <" + block + "> times: " + times); Err.pr("\tcurrentBlock: " + currentBlock); Err.pr("\tblock that has table: " + block); Err.pr("\tcurrent operation: " + currentOperation); Err.pr("\tcurrent state: " + currentState); Err.pr("\tidxCurrentRow: " + idxCurrentRow); if (times == 39) { Err.debug(); } } if (currentOperation == OperationEnum.INSERT_AFTER_PLACE || currentOperation == OperationEnum.INSERT_AT_PLACE) { if (block == currentBlock) { int index = -99; /* We don't do this for field, so lets not do it for table either if(currentOperation == OperationEnum.INSERT || currentOperation == OperationEnum.INSERT_IGNORE) { index = block.getIndex() + 1; } else */ { index = block.getIndex(); } usersModel.acceptEdit(); usersModel.fireTableRowsInserted(index, index); // Was trying to select the row on the table. Doing at the post operation performed // trigger (see SdzDsgnr for this) actually works, so as there's a workaround // we've left this as a slight note Err.pr( SdzNote.AUTO_SELECT_TABLE_ROW_AFTER_INSERT, "Do we actually need access to the JTable if wanted to do this here?"); // usersModel.fireRowChangedTo(index); Err.pr("Inserting a row s/know to move to it as well..."); Err.pr(SdzNote.SET_DISPLAY_ON_TABLE, "blankoutDisplay, have changed row to " + index); } else { // For example when insert master usersModel.fireTableDataChanged( "blankoutDisplay because of an " + "INSERT on different block to current, because " + reason); } } else if (currentOperation == OperationEnum.REMOVE /* && block == currentBlock*/) { /* * Do not want to fireTableDataChanged(), as this would lead to the * edited data being written ie. setValueAt() being called. */ usersModel.rejectEdit(); if ( /* (currentState.isNavigating() || currentState.isNew()) ||*/ currentState == StateEnum.FROZEN) { // When do this then model will no longer have the extra artificial // inserted row, and fireTableRowsDeleted will work usersModel.fireTableRowsDeleted(idxCurrentRow, idxCurrentRow); } } else if (currentOperation == OperationEnum.EXECUTE_QUERY) { /* * As above */ usersModel.rejectEdit(); usersModel.fireTableDataChanged("blankoutDisplay because of EXECUTE_QUERY because " + reason); } else if ((currentOperation == OperationEnum.NEXT || currentOperation == OperationEnum.PREVIOUS) && currentState.isNavigating()) { usersModel.fireTableDataChanged("blankoutDisplay because of NEXT/PREVIOUS because " + reason); } else if (currentOperation == OperationEnum.REFRESH) { Err.pr( /*SdzNote.SET_DISPLAY_ON_TABLE*/ false, "@@ blankoutDisplay for op " + currentOperation); usersModel.fireTableDataChanged( row, row, "blankoutDisplay for op " + currentOperation + " because " + reason); } else { Err.pr( /*SdzNote.SET_DISPLAY_ON_TABLE*/ false, "@@ blankoutDisplay, default as op was " + currentOperation); usersModel.fireTableDataChanged( "blankoutDisplay because of Un-programmed for op " + currentOperation + " because " + reason); } }
public Object getValueAt(int row, int col) { Object result = null; if (row < getRowCount()) { pr("{{ row " + row + " is less than getRowCount() " + getRowCount(), true); if (!TableSignatures.useNew(getTableControl()) && row == applyInsertModeForCursor(block.getIndex())) { pr( "{{ for row " + row + " col " + col + ", getting from special insert buffer, actual index is " + block.getIndex(), true); TableIdEnum id = IdEnum.newTable(getTableControl(), row, col, getColumnClass(col), null); result = TableSignatures.getText(id); } else { pr("{{ for row " + row + " col " + col + ", getting directly from database table", true); fillFlat(applyInsertModeForAllOtherRows(row)); AbstractTableItemAdapter ta = null; if (!doingNonVisual()) { ta = (AbstractTableItemAdapter) flatColumns.get(col); if (ta.getTableControl().getClass() == TableComp.class) { Err.error("Expected a Visual table, got " + ta.getTableControl().getClass().getName()); } } else { ta = (AbstractTableItemAdapter) nvFlatColumns.get(getNonVisualOrdinal()); if (ta.getTableControl().getClass() != TableComp.class) { Err.error( "Expected a Non-Visual table, got " + ta.getTableControl().getClass().getName()); } } pr("Getting database table value from DoAdapter() id " + ta.getDoAdapter().id, true); Object obj = ta.getStoredFlatObject(); pr("StoredFlatObject: " + obj, true); if (obj != null) { pr("\tis of type " + obj.getClass().getName(), true); } result = ta.getDoAdapter().getFieldValue(obj); } if (!doingNonVisual() && nvTables != null) { if (row != lastRowPainted) { int i = 0; for (Iterator iterator = nvTables.iterator(); iterator.hasNext(); i++) { TableComp tableComp = (TableComp) iterator.next(); setNonVisualOrdinal(i); tableComp.getModel().getValueAt(row, 0); setNonVisualOrdinal(VISUAL_MODE); } lastRowPainted = row; } } } else { Print.pr("Want row " + row); Print.pr("Row count is " + getRowCount()); Err.error("Table asking for a row that's not there: <" + row + "> for block " + block); } if (result != null) { pr( "Value at " + col + ", " + row + " is " + result + " of type " + result.getClass().getName() + " from ID:" + id); } return result; }