use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectPreferencePage method createFieldEditors.
/**
* Creates the field editors. Field editors are abstractions of the common
* GUI blocks needed to manipulate various types of preferences. Each field
* editor knows how to save and restore itself.
*/
@Override
public void createFieldEditors() {
final HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
StringFieldEditor usernameEditor = new StringFieldEditor(PreferenceConstants.HALE_CONNECT_USERNAME, "&User name:", getFieldEditorParent());
addField(usernameEditor);
usernameEditor.getTextControl(getFieldEditorParent()).addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
clearResult();
}
});
PasswordFieldEditor passwordEditor = new PasswordFieldEditor(PreferenceConstants.SECURE_NODE_NAME, PreferenceConstants.HALE_CONNECT_PASSWORD, // $NON-NLS-1$
"&Password:", getFieldEditorParent());
addField(passwordEditor);
passwordEditor.getTextControl().addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
clearResult();
}
});
Link link = new Link(getFieldEditorParent(), SWT.NONE);
link.setText("Not registered yet? <a href=\"https://www.haleconnect.com\">Create an account.</a>");
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(e.text));
} catch (PartInitException | MalformedURLException e1) {
setResultError("Error opening external browser. Please visit https://www.haleconnect.com to register.");
}
}
});
link.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
resultLabel = new Label(getFieldEditorParent(), SWT.NONE);
resultLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
clearResult();
Button validate = new Button(getFieldEditorParent(), SWT.NONE);
validate.setText("Validate credentials");
Button clear = new Button(getFieldEditorParent(), SWT.NONE);
clear.setText("Clear credentials");
validate.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
try {
String username = HaleConnectUIPlugin.getStoredUsername();
String password = HaleConnectUIPlugin.getStoredPassword();
if (hcs.verifyCredentials(username, password)) {
setResultSuccess("Credentials are valid.");
} else {
setResultError("Credentials were rejected.");
}
} catch (HaleConnectException ex) {
log.userError("Error accessing hale connect", ex);
} catch (StorageException ex) {
log.userError("Error accessing secure storage", ex);
}
}
});
clear.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
if (MessageDialog.openConfirm(getShell(), "Remove credentials", "This will remove the stored credentials and log you out.")) {
usernameEditor.setStringValue("");
passwordEditor.getTextControl().setText("");
performApply();
clearResult();
hcs.clearSession();
log.userInfo("Credentials removed.");
}
}
});
if (hcs.isLoggedIn()) {
setResult(MessageFormat.format("Logged in as \"{0}\"", hcs.getSession().getUsername()));
}
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectSource method updateLoginStatus.
private void updateLoginStatus() {
HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
selectProjectButton.setEnabled(hcs.isLoggedIn());
if (hcs.isLoggedIn()) {
loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN));
loginStatusLabel.setText(MessageFormat.format("Logged in as {0}", hcs.getSession().getUsername()));
} else {
loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
loginStatusLabel.setText("You are not logged in to hale connect. Please login before opening a project.");
}
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectSource method createControls.
/**
* @see ImportSource#createControls(Composite)
*/
@Override
public void createControls(Composite parent) {
parent.setLayout(new GridLayout(3, false));
HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
/*
* Login status label
*/
loginStatusLabel = new Label(parent, SWT.NONE);
loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
loginButton = new Button(parent, SWT.PUSH);
loginButton.setText("Login");
loginButton.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
HaleConnectLoginDialog loginDialog = HaleConnectLoginHandler.createLoginDialog(Display.getCurrent().getActiveShell());
if (loginDialog.open() == Dialog.OK) {
HaleConnectLoginHandler.performLogin(loginDialog);
updateLoginStatus();
}
}
});
/*
* Project name text field
*/
projectName = new StringFieldEditor("project", "Project", parent) {
// the following methods are overridden so the button
// may appear on the same line
@Override
public int getNumberOfControls() {
return super.getNumberOfControls() + 1;
}
@Override
protected void doFillIntoGrid(Composite parent, int numColumns) {
super.doFillIntoGrid(parent, numColumns - 1);
}
};
projectName.setEmptyStringAllowed(false);
projectName.setErrorMessage("Please select a project before continuing.");
projectName.setPage(getPage());
projectName.getTextControl(parent).setEditable(false);
projectName.getTextControl(parent).addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
selectProject();
}
});
projectName.setPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(FieldEditor.IS_VALID)) {
getPage().setMessage(null);
updateState(false);
} else if (event.getProperty().equals(FieldEditor.VALUE)) {
getPage().setMessage(null);
updateState(false);
}
}
});
/*
* Select project button
*/
selectProjectButton = new Button(parent, SWT.PUSH);
selectProjectButton.setText("Select");
selectProjectButton.setToolTipText("Select project");
selectProjectButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
selectProjectButton.setEnabled(hcs.isLoggedIn());
selectProjectButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selectProject();
}
});
/*
* Supported types
*/
supportedTypes = new HashSet<IContentType>();
if (getConfiguration().getContentType() != null) {
supportedTypes.add(getConfiguration().getContentType());
} else {
// set content types for file field
Collection<IOProviderDescriptor> factories = getConfiguration().getFactories();
for (IOProviderDescriptor factory : factories) {
supportedTypes.addAll(factory.getSupportedTypes());
}
}
// types combo
Composite group = new Composite(parent, SWT.NONE);
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
group.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create());
// label
Label providerLabel = new Label(parent, SWT.NONE);
providerLabel.setText("Import as");
// create provider combo
ComboViewer providers = createProviders(parent);
providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
updateLoginStatus();
// initial state update
updateState(true);
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectLoginContentProvider method createContent.
/**
* @see org.eclipse.ui.intro.config.IIntroContentProvider#createContent(java.lang.String,
* java.io.PrintWriter)
*/
@Override
public void createContent(String id, PrintWriter out) {
if (disposed) {
return;
}
String username = "";
String password = "";
try {
username = HaleConnectUIPlugin.getStoredUsername();
password = HaleConnectUIPlugin.getStoredPassword();
} catch (StorageException e) {
log.error("Failed to retrieve hale connect credentials from preferences store", e);
}
HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
VelocityEngine velocityEngine = new VelocityEngine();
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("id", id);
velocityContext.put("username", username);
velocityContext.put("password", password);
velocityContext.put("loggedIn", hcs.isLoggedIn());
velocityContext.put("pluginId", "eu.esdihumboldt.hale.io.haleconnect.ui");
velocityContext.put("actionClass", this.getClass().getName());
InputStreamReader templateReader;
try {
templateReader = new InputStreamReader(HaleConnectLoginContentProvider.class.getResourceAsStream("templates/welcome-login.vm"), "UTF-8");
velocityEngine.init();
velocityEngine.evaluate(velocityContext, out, "hale-connect-login", templateReader);
} catch (Exception e) {
log.error("Error rendering template for hale connect login section.", e);
out.print("Error rendering template for hale connect login section.");
}
}
use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.
the class HaleConnectLoginHandler method performLogin.
/**
* Login to hale connect using the credentials entered in the given
* {@link HaleConnectLoginDialog}.
*
* @param loginDialog Login dialog with credentials
* @return true if successfully logged in
*/
public static boolean performLogin(HaleConnectLoginDialog loginDialog) {
HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
String username = loginDialog.getUsername();
String password = loginDialog.getPassword();
boolean saveCredentials = loginDialog.isSaveCredentials();
try {
if (hcs.login(username, password)) {
loginDialog.close();
if (saveCredentials) {
try {
HaleConnectUIPlugin.storeUsername(username);
HaleConnectUIPlugin.storePassword(password);
} catch (StorageException e) {
log.error("hale connect credentials could not be saved.", e);
}
}
log.userInfo("Login to hale connect successful.");
return true;
} else {
log.userWarn("Login to hale connect failed, please check the credentials.");
}
} catch (HaleConnectException e) {
log.userError("An error occurred while trying to login to hale connect", e);
}
return false;
}
Aggregations