use of io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category in project arduino-eclipse-plugin by Sloeber.
the class LibrarySelectionPage method createTree.
public void createTree(Composite parent) {
// filtering applied to all columns
PatternFilter filter = new PatternFilter() {
@Override
protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
int numberOfColumns = ((TreeViewer) viewer1).getTree().getColumnCount();
boolean isMatch = false;
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
String labelText = LibraryLabelProvider.getColumnText(element, columnIndex);
isMatch |= wordMatches(labelText);
}
return isMatch;
}
};
this.tree = new FilteredTree(parent, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true, true) {
@Override
protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
viewer1.setCheckStateProvider(new LibraryCheckProvider());
viewer1.setLabelProvider(new LibraryLabelProvider());
viewer1.setContentProvider(new LibraryContentProvider());
return viewer1;
}
};
this.viewer = this.tree.getViewer();
this.viewer.setInput(this.libs);
TreeColumn name = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
name.setWidth(400);
TreeColumn version = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
version.setWidth(100);
// create the editor and set its attributes
this.editor = new TreeEditor(this.viewer.getTree());
this.editor.horizontalAlignment = SWT.LEFT;
this.editor.grabHorizontal = true;
this.editor.setColumn(1);
// this ensures the tree labels are displayed correctly
this.viewer.refresh(true);
// enable tooltips
ColumnViewerToolTipSupport.enableFor(this.viewer);
// tree interactions listener
this.viewer.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (LibrarySelectionPage.this.editor.getEditor() != null) {
LibrarySelectionPage.this.editor.getEditor().dispose();
}
final TreeItem item = event.item instanceof TreeItem ? (TreeItem) event.item : null;
if (item != null && event.detail == SWT.CHECK) {
if (item.getData() instanceof LibraryTree.Category) {
Category category = ((LibraryTree.Category) item.getData());
item.setGrayed(false);
for (LibraryTree.Library child : category.getLibraries()) {
if (item.getChecked()) {
child.setVersion(child.getLatest());
} else {
child.setVersion((ArduinoLibraryVersion) null);
}
}
for (TreeItem child : item.getItems()) {
child.setChecked(item.getChecked());
child.setText(1, ((LibraryTree.Library) child.getData()).getVersionString());
}
} else {
if (item.getData() instanceof LibraryTree.Library) {
Library lib = ((LibraryTree.Library) item.getData());
if (item.getChecked()) {
lib.setVersion(lib.getLatest());
} else {
lib.setVersion((ArduinoLibraryVersion) null);
}
item.setText(0, lib.getName());
item.setText(1, lib.getVersionString());
verifySubtreeCheckStatus(item.getParentItem());
}
}
}
if (item != null && item.getItemCount() == 0 && item.getChecked()) {
// Create the dropdown and add data to it
final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY);
Library selectedLib = ((LibraryTree.Library) item.getData());
for (ArduinoLibraryVersion version1 : selectedLib.getVersions()) {
combo.add(version1.getVersion().toString());
}
ArduinoLibraryVersion displayVersion = selectedLib.getVersion();
if (displayVersion == null) {
displayVersion = selectedLib.getLatest();
selectedLib.setVersion(displayVersion);
item.setText(0, selectedLib.getName());
}
combo.select(combo.indexOf(displayVersion.getVersion().toString()));
// Compute the width for the editor
// Also, compute the column width, so that the dropdown fits
// Set the focus on the dropdown and set into the editor
combo.setFocus();
LibrarySelectionPage.this.editor.setEditor(combo, item, 1);
// Add a listener to set the selected item back into the
// cell
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event1) {
LibraryTree.Library lib = (LibraryTree.Library) item.getData();
lib.setVersion(new VersionNumber(combo.getText()));
item.setText(1, lib.getVersionString());
item.setText(0, lib.getName());
// Item selected: end the editing session
combo.dispose();
}
});
}
}
});
}
use of io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category in project arduino-eclipse-plugin by Sloeber.
the class LibrarySelectionPage method performOk.
@Override
public boolean performOk() {
if (this.isJobRunning == true) {
// $NON-NLS-1$
MessageDialog.openInformation(// $NON-NLS-1$
getShell(), // $NON-NLS-1$
"Library Manager", // $NON-NLS-1$
"Library Manager is busy. Please wait some time...");
return false;
}
this.isJobRunning = true;
Job job = new Job(Messages.ui_Adopting_arduino_libraries) {
@Override
protected IStatus run(IProgressMonitor monitor) {
MultiStatus status = new MultiStatus(PLUGIN_ID, 0, Messages.ui_installing_arduino_libraries, null);
Set<ArduinoLibraryVersion> toRemoveLibs = new HashSet<>();
Set<ArduinoLibraryVersion> toInstallLibs = new HashSet<>();
for (Category category : libs.categories.values()) {
for (Library library : category.libraries.values()) {
ArduinoLibraryVersion installedVersion = library.getInstalledVersion();
ArduinoLibraryVersion toInstalVersion = library.getVersion();
if ((installedVersion != null) && (installedVersion.compareTo(toInstalVersion) != 0)) {
toRemoveLibs.add(installedVersion);
}
if ((toInstalVersion != null) && (toInstalVersion.compareTo(installedVersion) != 0)) {
toInstallLibs.add(toInstalVersion);
}
}
}
return LibraryManager.updateLibraries(toRemoveLibs, toInstallLibs, monitor, status);
}
};
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
LibrarySelectionPage.this.isJobRunning = false;
}
});
job.setUser(true);
job.schedule();
return true;
}
Aggregations