// Set focus to search field
searchTextInput.requestFocus();
// Check if an import is in progress and refresh the progress bar if it is
MediaImportStatus status = Client.create(config).resource(HOSTURL + "/mediaimportmodules/" + selectedImporterButton.getSelectedItem()).accept(MediaType.APPLICATION_JSON).get(MediaImportStatus.class);
if (status != null) {
startImportProgressBar();
}
// Setup listeners for Import/Abort button
importButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
if (importTask != null) {
abortImport(selectedImporterButton.getSelectedItem().toString());
} else {
startImport(selectedImporterButton.getSelectedItem().toString());
}
}
});
// Setup listeners for close button
closeButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
getWindow().close();
}
});
// When search button is clicked, we want to search for both artists, releases and works
searchButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
searchArtists(searchTextInput.getText(), null, null);
searchReleases(searchTextInput.getText(), null, null);
searchWorks(searchTextInput.getText(), null, null);
}
});
// When search field is changed, we want to search for both artists, releases and works
searchTextInput.getTextInputContentListeners().add(new TextInputContentListener.Adapter() {
@Override
public void textChanged(TextInput textInput) {
if (textInput.getText() != null && textInput.getText().length() > 2) {
searchArtists(searchTextInput.getText(), null, null);
searchReleases(searchTextInput.getText(), null, null);
searchWorks(searchTextInput.getText(), null, null);
}
}
});
// Selection changes in release results should trigger refresh of artists and works
releaseResultsTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener.Adapter() {
@Override
public void selectedRangesChanged(TableView tableView, Sequence<Span> spanSequence) {
Release release = (Release) tableView.getSelectedRow();
if(release!=null) {
searchTextInput.setText("");
searchArtists(null, null, release.getId());
searchWorks(null, null, release.getId());
}
}
});
// Selection changes in artist results should trigger refresh of releases and works
artistResultsTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener.Adapter() {
@Override
public void selectedRangesChanged(TableView tableView, Sequence<Span> spanSequence) {
Artist artist = (Artist) tableView.getSelectedRow();
if(artist!=null) {
searchTextInput.setText("");
searchReleases(null, artist.getId(), null);
searchWorks(null, artist.getId(), null);
}
}
});
// Selection changes in work results should trigger refresh of artists and releases
workResultsTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener.Adapter() {
@Override
public void selectedRangesChanged(TableView tableView, Sequence<Span> spanSequence) {
Work work = (Work) tableView.getSelectedRow();
if(work!=null) {
searchTextInput.setText("");
searchReleases(null, null, work.getId());
searchArtists(null, work.getId(), null);
}
}
});
// Double click handler for releases
releaseResultsTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
try {
if (count == 2) {
Release release = (Release) releaseResultsTableView.getSelectedRow();
BXMLSerializer wtkxSerializer = new BXMLSerializer();
EditReleaseWindow window = (EditReleaseWindow) wtkxSerializer.readObject(getClass().getResource("EditReleaseWindow.bxml"),new Resources(resources,EditReleaseWindow.class.getName()));
window.open(getDisplay(), getWindow(), release);
return true;
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SerializationException e) {
throw new RuntimeException(e);
}
return false;
}
});
selectedImporterButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener.Adapter() {
@Override
public void selectedIndexChanged(ListButton listButton, int i) {
MediaImportStatus status = Client.create(config).resource(HOSTURL + "/mediaimportmodules/" + selectedImporterButton.getSelectedItem()).accept(MediaType.APPLICATION_JSON).get(MediaImportStatus.class);
if (status != null) {
startImportProgressBar();
}
}
});