Skip to content

Commit

Permalink
Label provider consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Sep 25, 2023
1 parent b5b0808 commit 777094e
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions modules/spin-tools/src/com/maccasoft/propeller/FileBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ITreeViewerListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.TreeExpansionEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

Expand All @@ -58,24 +58,6 @@ public File[] getElements() {
}
}

class FileLabelProvider extends LabelProvider {

@Override
public String getText(Object element) {
String name = ((File) element).getName();
if (name == null || name.length() == 0) {
name = ((File) element).getPath();
}
return name;
}

@Override
public Image getImage(Object element) {
return ImageRegistry.getImageForFile((File) element);
}

}

class FileTreeContentProvider implements ITreeContentProvider {

@Override
Expand Down Expand Up @@ -231,7 +213,22 @@ public FileBrowser(Composite parent) {
hiddenExtensions.add(".binary");

viewer = new TreeViewer(parent);
viewer.setLabelProvider(new FileLabelProvider());
viewer.setLabelProvider(new StyledCellLabelProvider() {

@Override
public void update(ViewerCell cell) {
File element = (File) cell.getElement();

String name = element.getName();
if (name == null || name.length() == 0) {
name = element.getPath();
}
cell.setText(name);

cell.setImage(ImageRegistry.getImageForFile(element));
}

});
viewer.setComparator(new FileComparator());
viewer.setContentProvider(new FileTreeContentProvider());
viewer.setUseHashlookup(true);
Expand Down

0 comments on commit 777094e

Please sign in to comment.