Skip to content

Commit

Permalink
Style fixes eclipse-platform#882
Browse files Browse the repository at this point in the history
  • Loading branch information
basilevs committed Jan 22, 2024
1 parent 576733b commit b1fe223
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -1635,7 +1631,7 @@ TreeItem _getItem(TreeItem parentItem, long parentIter, List<TreeItem> 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 ();
Expand Down Expand Up @@ -1815,7 +1811,7 @@ int getItemHeightInPixels () {
* </ul>
*/
public TreeItem [] getItems () {
checkWidget();
checkWidget ();
return _getItems (null, roots, 0);
}

Expand All @@ -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);
Expand All @@ -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 ()]);
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2775,14 +2771,14 @@ void register () {
void _releaseItems (long parentIter, List<TreeItem> 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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<columns.length; i++) {
if (columns[i] != null) columns[i].setOrientation (create);
if (columns [i] != null) columns [i].setOrientation (create);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class TreeItem extends Item {
Font[] cellFont;
String [] strings;
boolean cached, grayed, isExpanded, updated, settingData;
private final List<TreeItem> items = new ArrayList<>();
private final List<TreeItem> items = new ArrayList<> ();
private final TreeItem parentItem;
static final int EXPANDER_EXTRA_PADDING = 4;

Expand Down Expand Up @@ -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;
Expand All @@ -180,7 +184,7 @@ public TreeItem (TreeItem parentItem, int style, int index) {
List<TreeItem> siblings = getSiblings ();
if (iter == 0) {
if (index == -1) {
index = siblings.size();
index = siblings.size ();
}
/*
* Try to achieve maximum possible performance in bulk insert scenarios.
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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 ();
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -1083,15 +1088,15 @@ 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);
long indices = GTK.gtk_tree_path_get_indices (path);
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 {
Expand Down Expand Up @@ -1150,7 +1155,7 @@ public void dispose () {
*/
public void removeAll () {
checkWidget ();
setItemCount(0);
setItemCount (0);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -1742,24 +1747,24 @@ public void setText (String [] strings) {
}
}

List<TreeItem> getSiblings() {
List<TreeItem> getSiblings () {
if (parentItem != null) {
return parentItem.items;
} else {
return parent.roots;
}
}

static final <T> void ensureSizeAtLeast(List<T> list, int size, T fill) {
int extra = size - list.size();
static final <T> void ensureSizeAtLeast (List<T> 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<TreeItem> getKnownChildrenRecursively() {
return items.stream()
.filter(Objects::nonNull).
flatMap( item -> Stream.concat(Stream.of(item), item.getKnownChildrenRecursively()));
Stream<TreeItem> getKnownChildrenRecursively () {
return items.stream ()
.filter (Objects::nonNull).
flatMap ( item -> Stream.concat (Stream.of (item), item.getKnownChildrenRecursively ()));
}
}

0 comments on commit b1fe223

Please sign in to comment.