externalizes strings
This commit is contained in:
parent
31fd54c6be
commit
25064f9744
|
@ -95,6 +95,17 @@ public class Messages extends NLS {
|
||||||
public static String marker_text;
|
public static String marker_text;
|
||||||
public static String rel_arrow;
|
public static String rel_arrow;
|
||||||
public static String rel_arrow_highlite;
|
public static String rel_arrow_highlite;
|
||||||
|
public static String UpdateHandler_URI;
|
||||||
|
public static String UpdateHandler_10;
|
||||||
|
public static String UpdateHandler_11;
|
||||||
|
public static String UpdateHandler_2;
|
||||||
|
public static String UpdateHandler_3;
|
||||||
|
public static String UpdateHandler_4;
|
||||||
|
public static String UpdateHandler_5;
|
||||||
|
public static String UpdateHandler_6;
|
||||||
|
public static String UpdateHandler_7;
|
||||||
|
public static String UpdateHandler_8;
|
||||||
|
public static String UpdateHandler_9;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// initialize resource bundle
|
// initialize resource bundle
|
||||||
|
|
|
@ -21,13 +21,14 @@ import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
|
|
||||||
|
import com.minres.scviewer.e4.application.Messages;
|
||||||
|
|
||||||
public class UpdateHandler {
|
public class UpdateHandler {
|
||||||
|
|
||||||
boolean cancelled = false;
|
boolean cancelled = false;
|
||||||
|
|
||||||
@Execute
|
@Execute
|
||||||
public void execute(IProvisioningAgent agent, UISynchronize sync, IWorkbench workbench) {
|
public void execute(IProvisioningAgent agent, UISynchronize sync, IWorkbench workbench) {
|
||||||
// update using a progress monitor
|
|
||||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||||
@Override
|
@Override
|
||||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||||
|
@ -44,17 +45,18 @@ public class UpdateHandler {
|
||||||
private IStatus update(IProvisioningAgent agent, IProgressMonitor monitor, UISynchronize sync,
|
private IStatus update(IProvisioningAgent agent, IProgressMonitor monitor, UISynchronize sync,
|
||||||
IWorkbench workbench) {
|
IWorkbench workbench) {
|
||||||
ProvisioningSession session = new ProvisioningSession(agent);
|
ProvisioningSession session = new ProvisioningSession(agent);
|
||||||
// update the whole running profile, otherwise specify IUs
|
|
||||||
UpdateOperation operation = new UpdateOperation(session);
|
UpdateOperation operation = new UpdateOperation(session);
|
||||||
try {
|
try {
|
||||||
operation.getProvisioningContext().setArtifactRepositories(new URI("http://https://minres.github.io/SCViewer/repository"));
|
operation.getProvisioningContext().setArtifactRepositories(new URI(Messages.UpdateHandler_URI));
|
||||||
operation.getProvisioningContext().setMetadataRepositories(new URI("http://https://minres.github.io/SCViewer/repository"));
|
operation.getProvisioningContext().setMetadataRepositories(new URI(Messages.UpdateHandler_URI));
|
||||||
} catch (URISyntaxException e) {}
|
} catch (URISyntaxException e) {
|
||||||
SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
|
}
|
||||||
// check if updates are available
|
SubMonitor sub = SubMonitor.convert(monitor, Messages.UpdateHandler_2, 200);
|
||||||
IStatus status = operation.resolveModal(sub.newChild(100));
|
IStatus status = operation.resolveModal(sub.newChild(100));
|
||||||
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
|
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
|
||||||
showMessage(sync, "Nothing to update");
|
sync.syncExec(() -> {
|
||||||
|
MessageDialog.openInformation(null, Messages.UpdateHandler_10, Messages.UpdateHandler_3);
|
||||||
|
});
|
||||||
return Status.CANCEL_STATUS;
|
return Status.CANCEL_STATUS;
|
||||||
} else {
|
} else {
|
||||||
ProvisioningJob provisioningJob = operation.getProvisioningJob(sub.newChild(100));
|
ProvisioningJob provisioningJob = operation.getProvisioningJob(sub.newChild(100));
|
||||||
|
@ -62,8 +64,8 @@ public class UpdateHandler {
|
||||||
sync.syncExec(new Runnable() {
|
sync.syncExec(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean performUpdate = MessageDialog.openQuestion(null, "Updates available",
|
boolean performUpdate = MessageDialog.openQuestion(null, Messages.UpdateHandler_4,
|
||||||
"There are updates available. Do you want to install them now?");
|
Messages.UpdateHandler_5);
|
||||||
if (performUpdate) {
|
if (performUpdate) {
|
||||||
provisioningJob.addJobChangeListener(new JobChangeAdapter() {
|
provisioningJob.addJobChangeListener(new JobChangeAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,22 +76,21 @@ public class UpdateHandler {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean restart = MessageDialog.openQuestion(null,
|
boolean restart = MessageDialog.openQuestion(null,
|
||||||
"Updates installed, restart?",
|
Messages.UpdateHandler_6, Messages.UpdateHandler_7);
|
||||||
"Updates have been installed successfully, do you want to restart?");
|
|
||||||
if (restart) {
|
if (restart) {
|
||||||
workbench.restart();
|
workbench.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
showError(sync, event.getResult().getMessage());
|
sync.syncExec(() -> {
|
||||||
|
MessageDialog.openInformation(null, Messages.UpdateHandler_11,
|
||||||
|
event.getResult().getMessage());
|
||||||
|
});
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// since we switched to the UI thread for interacting with the user
|
|
||||||
// we need to schedule the provisioning thread, otherwise it would
|
|
||||||
// be executed also in the UI thread and not in a background thread
|
|
||||||
provisioningJob.schedule();
|
provisioningJob.schedule();
|
||||||
} else {
|
} else {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
@ -98,43 +99,22 @@ public class UpdateHandler {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (operation.hasResolved()) {
|
if (operation.hasResolved()) {
|
||||||
showError(sync, "Couldn't get provisioning job: " + operation.getResolutionResult());
|
sync.syncExec(() -> {
|
||||||
|
MessageDialog.openInformation(null, Messages.UpdateHandler_11,
|
||||||
|
Messages.UpdateHandler_8 + operation.getResolutionResult());
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
showError(sync, "Couldn't resolve provisioning job");
|
sync.syncExec(() -> {
|
||||||
|
MessageDialog.openInformation(null, Messages.UpdateHandler_11, Messages.UpdateHandler_9);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
// reset cancelled flag
|
|
||||||
cancelled = false;
|
cancelled = false;
|
||||||
return Status.CANCEL_STATUS;
|
return Status.CANCEL_STATUS;
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMessage(UISynchronize sync, final String message) {
|
|
||||||
// as the provision needs to be executed in a background thread
|
|
||||||
// we need to ensure that the message dialog is executed in
|
|
||||||
// the UI thread
|
|
||||||
sync.syncExec(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MessageDialog.openInformation(null, "Information", message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showError(UISynchronize sync, final String message) {
|
|
||||||
// as the provision needs to be executed in a background thread
|
|
||||||
// we need to ensure that the message dialog is executed in
|
|
||||||
// the UI thread
|
|
||||||
sync.syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MessageDialog.openError(null, "Error", message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,4 +89,14 @@ marker=Marker
|
||||||
marker_text=Marker TExt
|
marker_text=Marker TExt
|
||||||
rel_arrow=Relation arrow
|
rel_arrow=Relation arrow
|
||||||
rel_arrow_highlite=highlighted Relation arrorw
|
rel_arrow_highlite=highlighted Relation arrorw
|
||||||
|
UpdateHandler_URI=http://https://minres.github.io/SCViewer/repository
|
||||||
|
UpdateHandler_10=Information
|
||||||
|
UpdateHandler_11=Error
|
||||||
|
UpdateHandler_2=Checking for application updates...
|
||||||
|
UpdateHandler_3=Nothing to update
|
||||||
|
UpdateHandler_4=Updates available
|
||||||
|
UpdateHandler_5=There are updates available. Do you want to install them now?
|
||||||
|
UpdateHandler_6=Updates installed, restart?
|
||||||
|
UpdateHandler_7=Updates have been installed successfully, do you want to restart?
|
||||||
|
UpdateHandler_8=Couldn't get provisioning job:
|
||||||
|
UpdateHandler_9=Couldn't resolve provisioning job
|
||||||
|
|
Loading…
Reference in New Issue