From b1fe223d61991848899fad853eb598ecaca46ab2 Mon Sep 17 00:00:00 2001 From: Vasili Gulevich Date: Mon, 22 Jan 2024 20:02:04 +0000 Subject: [PATCH] Style fixes #882 --- .../gtk/org/eclipse/swt/widgets/Tree.java | 44 ++++++------- .../gtk/org/eclipse/swt/widgets/TreeItem.java | 61 ++++++++++--------- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 8031678182..cc8b8b4501 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -202,7 +202,7 @@ TreeItem _getItemByPath (long path) { C.memmove (indices, GTK.gtk_tree_path_get_indices (path), 4*depth); TreeItem item = depth > 0 ? getItem (indices [0]) : null; for (int i = 1; i < depth; i++) { - item = item.getItem( indices [i]); + item = item.getItem (indices [i]); } return item; } @@ -650,7 +650,7 @@ void copyModel (long oldModel, int oldStart, long newModel, int newStart, TreeIt } } // recurse through children - copyModel(oldModel, oldStart, newModel, newStart, item, newIterator, modelLength); + copyModel (oldModel, oldStart, newModel, newStart, item, newIterator, modelLength); if (item!= null) { item.handle = newIterator; @@ -911,10 +911,6 @@ void createItem (TreeColumn column, int index) { updateHeaderCSS(); } -/** - * The fastest way to insert many items is documented in {@link TreeItem#TreeItem(org.eclipse.swt.widgets.Tree,int,int)} - * and {@link TreeItem#setItemCount} - */ void itemCreated (TreeItem item) { modelChanged = true; @@ -1128,7 +1124,7 @@ void destroyItem (TreeColumn column) { long [] types = getColumnTypes (1); long newModel = GTK.gtk_tree_store_newv (types.length, types); if (newModel == 0) error (SWT.ERROR_NO_HANDLES); - copyModel(oldModel, column.modelIndex, newModel, FIRST_COLUMN, null, (long )0, FIRST_COLUMN + CELL_TYPES); + copyModel (oldModel, column.modelIndex, newModel, FIRST_COLUMN, null, (long )0, FIRST_COLUMN + CELL_TYPES); GTK.gtk_tree_view_set_model (handle, newModel); setModel (newModel); createColumn (null, 0); @@ -1619,7 +1615,7 @@ public boolean getHeaderVisible () { * @since 3.1 */ public TreeItem getItem (int index) { - checkWidget(); + checkWidget (); if (index < 0) error (SWT.ERROR_INVALID_RANGE); if (index >= roots.size ()) error (SWT.ERROR_INVALID_RANGE); @@ -1635,7 +1631,7 @@ TreeItem _getItem(TreeItem parentItem, long parentIter, List siblings, long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ()); try { if (!GTK.gtk_tree_model_iter_nth_child (modelHandle, iter, parentIter, index)) error (SWT.ERROR_INVALID_RANGE); - result = new TreeItem(this, parentItem, SWT.NONE, index, iter); + result = new TreeItem (this, parentItem, SWT.NONE, index, iter); TreeItem existing = siblings.set (index, result); if (existing != null) { existing.dispose (); @@ -1815,7 +1811,7 @@ int getItemHeightInPixels () { * */ public TreeItem [] getItems () { - checkWidget(); + checkWidget (); return _getItems (null, roots, 0); } @@ -1827,8 +1823,8 @@ int getItemHeightInPixels () { boolean valid = GTK.gtk_tree_model_iter_children (modelHandle, iter, parentIter); while (valid) { if (items.size () <= i || items.get (i) == null) { - new TreeItem(this, parentItem, SWT.NONE, i, iter); - if (items.get (i) == null) throw new AssertionError("Item constructor should update sibling list"); + new TreeItem (this, parentItem, SWT.NONE, i, iter); + if (items.get (i) == null) throw new AssertionError ("Item constructor should update sibling list"); } i++; valid = GTK.gtk_tree_model_iter_next (modelHandle, iter); @@ -1837,7 +1833,7 @@ int getItemHeightInPixels () { OS.g_free (iter); } assert items.indexOf (null) < 0 : "All items should be hydrated"; - return items.toArray (new TreeItem [items.size()]); + return items.toArray (new TreeItem [items.size ()]); } /** @@ -2445,7 +2441,7 @@ long gtk_row_has_child_toggled (long model, long path, long iter) { * and use this callback, as it is invoked when a row has * gotten the first child row or lost its last child row. */ - TreeItem item = _getItemByPath(path); + TreeItem item = _getItemByPath (path); int childCount = GTK.gtk_tree_model_iter_n_children (modelHandle, item.handle); if (childCount != 0 && item.isExpanded) { OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW); @@ -2473,7 +2469,7 @@ long gtk_start_interactive_search(long widget) { @Override long gtk_test_collapse_row (long tree, long iter, long path) { - TreeItem item = _getItemByIter(iter); + TreeItem item = _getItemByIter (iter); Event event = new Event (); event.item = item; boolean oldModelChanged = modelChanged; @@ -2511,7 +2507,7 @@ long gtk_test_collapse_row (long tree, long iter, long path) { @Override long gtk_test_expand_row (long tree, long iter, long path) { - TreeItem item = _getItemByPath(path); + TreeItem item = _getItemByPath (path); Event event = new Event (); event.item = item; boolean oldModelChanged = modelChanged; @@ -2775,14 +2771,14 @@ void register () { void _releaseItems (long parentIter, List items) { for (TreeItem item: items) { if (item != null && !isDisposed ()) { - item.release(false); + item.release (false); } } } @Override void releaseChildren (boolean destroy) { - getKnownItemsRecursively().forEach(item -> { + getKnownItemsRecursively ().forEach (item -> { if (item != null && !item.isDisposed ()) { item.release (false); } @@ -2832,13 +2828,13 @@ public void removeAll () { OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (TreeItem item: new ArrayList<>(roots)) { - if (item != null && !item.isDisposed() ) { - item.release(false); + for (TreeItem item: new ArrayList<> (roots)) { + if (item != null && !item.isDisposed () ) { + item.release (false); } } - roots.clear(); + roots.clear (); if (!searchEnabled ()) { GTK.gtk_tree_view_set_search_column (handle, -1); @@ -3724,10 +3720,10 @@ void setModel (long newModel) { @Override void setOrientation (boolean create) { super.setOrientation (create); - getKnownItemsRecursively().forEach(item -> item.setOrientation (create)); + getKnownItemsRecursively ().forEach(item -> item.setOrientation (create)); if (columns != null) { for (int i=0; i items = new ArrayList<>(); + private final List items = new ArrayList<> (); private final TreeItem parentItem; static final int EXPANDER_EXTRA_PADDING = 4; @@ -167,6 +167,10 @@ public TreeItem (TreeItem parentItem, int style, int index) { this (checkNull (parentItem).parent, parentItem, style, checkIndex (index), 0); } +/** + * The fastest way to insert many items is documented in {@link TreeItem#TreeItem(org.eclipse.swt.widgets.Tree,int,int)} + * and {@link TreeItem#setItemCount} + */ TreeItem (Tree parent, TreeItem parentItem, int style, int index, long iter) { super (parent, style); this.parent = parent; @@ -180,7 +184,7 @@ public TreeItem (TreeItem parentItem, int style, int index) { List siblings = getSiblings (); if (iter == 0) { if (index == -1) { - index = siblings.size(); + index = siblings.size (); } /* * Try to achieve maximum possible performance in bulk insert scenarios. @@ -192,24 +196,25 @@ public TreeItem (TreeItem parentItem, int style, int index) { } else if (index == 0) { GTK.gtk_tree_store_prepend (parent.modelHandle, handle, parentIter); siblings.add (0, this); - } else if (siblings.size() == index) { - GTK.gtk_tree_store_append (parent.modelHandle, handle, parentIter); - siblings.add (this); - } else { + } else if (siblings.size () == index) { /* * Feature in GTK. It is much faster to append to a tree store * than to insert at the end using gtk_tree_store_insert(). */ + GTK.gtk_tree_store_append (parent.modelHandle, handle, parentIter); + siblings.add (this); + } else { GTK.gtk_tree_store_insert (parent.modelHandle, handle, parentIter, index); - siblings.add(index, this); + siblings.add (index, this); } - parent.itemCreated(this); + parent.itemCreated (this); } else { if (index < 0 || index >= siblings.size ()) error (SWT.ERROR_INVALID_RANGE); - C.memmove(handle, iter, GTK.GtkTreeIter_sizeof ()); - siblings.set(index, this); + C.memmove (handle, iter, GTK.GtkTreeIter_sizeof ()); + TreeItem preExisting = siblings.set (index, this); + assert preExisting == null : "Multiple TreeItems can't have same index"; } - assert treeStoreIndexOf() == index; + assert treeStoreIndexOf () == index; } catch (Throwable e) { OS.g_free (handle); handle = 0; @@ -365,7 +370,7 @@ public void clear (int index, boolean all) { checkWidget (); TreeItem item = items.get (index); if (item == null) return; - item.clear(); + item.clear (); if (all) { item.clearAll (all); } @@ -394,8 +399,8 @@ public void clearAll (boolean all) { checkWidget (); for (TreeItem item: items) { if (item != null) { - item.clear(); - if (all) item.clearAll(all); + item.clear (); + if (all) item.clearAll (all); } } } @@ -829,7 +834,7 @@ Rectangle getImageBoundsInPixels (int index) { public int getItemCount () { checkWidget(); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return items.size(); + return items.size (); } /** @@ -857,7 +862,7 @@ public TreeItem getItem (int index) { return parent._getItem(this, handle, items, index); } -TreeItem _peekItem(int index) { +TreeItem _peekItem (int index) { return items.get(index); } @@ -1083,7 +1088,7 @@ public int indexOf (TreeItem item) { return items.indexOf (item); } -private int treeStoreIndexOf() { +private int treeStoreIndexOf () { long path = GTK.gtk_tree_model_get_path (parent.modelHandle, handle); try { int depth = GTK.gtk_tree_path_get_depth (path); @@ -1091,7 +1096,7 @@ private int treeStoreIndexOf() { if (indices != 0) { int[] temp = new int [depth]; C.memmove (temp, indices, 4 * temp.length); - return temp[temp.length - 1]; + return temp [temp.length - 1]; } return -1; } finally { @@ -1150,7 +1155,7 @@ public void dispose () { */ public void removeAll () { checkWidget (); - setItemCount(0); + setItemCount (0); } /** @@ -1662,7 +1667,7 @@ public void setImage (Image [] images) { public void setItemCount (int count) { if (count < 0) error (SWT.ERROR_INVALID_RANGE); checkWidget (); - parent._setItemCount(this, this.handle, items, count); + parent._setItemCount (this, this.handle, items, count); } /** @@ -1742,7 +1747,7 @@ public void setText (String [] strings) { } } -List getSiblings() { +List getSiblings () { if (parentItem != null) { return parentItem.items; } else { @@ -1750,16 +1755,16 @@ List getSiblings() { } } -static final void ensureSizeAtLeast(List list, int size, T fill) { - int extra = size - list.size(); +static final void ensureSizeAtLeast (List list, int size, T fill) { + int extra = size - list.size (); if (extra > 0) { - list.addAll(Collections.nCopies(extra, fill)); + list.addAll (Collections.nCopies (extra, fill)); } } -Stream getKnownChildrenRecursively() { - return items.stream() - .filter(Objects::nonNull). - flatMap( item -> Stream.concat(Stream.of(item), item.getKnownChildrenRecursively())); +Stream getKnownChildrenRecursively () { + return items.stream () + .filter (Objects::nonNull). + flatMap ( item -> Stream.concat (Stream.of (item), item.getKnownChildrenRecursively ())); } }