}
return conversation;
}
+
+ /**
+ * Whether the current user has the role admin
+ *
+ * @return
+ */
+ public boolean isAdmin() {
+ // FIXME until we have rights implemented properly we do this
+ // by a simple string check. This has to change
+
+ return "admin".equals(getAuthenticatedUser().getUsername());
+ }
}
package eu.etaxonomy.taxeditor.ui.forms;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import org.apache.http.HttpException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.widgets.TableWrapData;
import eu.etaxonomy.cdm.common.UriUtils;
*/
protected ImageElement(CdmFormFactory formFactory, ICdmFormElement parentElement, URI imageUri, int style) {
super(formFactory, parentElement);
-
- setImageUri(imageUri);
- loadImage();
-
+
container = new Composite(getLayoutComposite(), style);
container.setLayoutData(CdmFormFactory.FILL(2, 1));
* <p>Setter for the field <code>imageUri</code>.</p>
*
* @param uri a {@link java.net.URI} object.
+ * @throws HttpException
+ * @throws IOException
*/
- public void setImageUri(URI uri) {
+ public void initImageUri(URI uri) throws IOException, HttpException {
this.imageUri = uri;
+ InputStream imageStream = UriUtils.getInputStream(imageUri);
+ image = new Image(Display.getCurrent(), imageStream);
}
loadImage(null);
}
+
+
public void loadImage(final Runnable postRunnable){
if(getImageUri() != null){
Job job = new Job("Loading image") {
}
}
- public IRunnableWithProgress getLoadImageRunnable(final Runnable postRunnable){
+
+
+ public void unloadImage(final Runnable postRunnable) {
+ Job job = new Job("Unloading image") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ IRunnableWithProgress runnable = getLoadImageRunnable(postRunnable);
+ try {
+ runnable.run(monitor);
+ } catch (Exception e) {
+ StoreUtil.errorDialog("Could not unload image", getClass(), e.getMessage() + ": " + getImageUri(), e);
+ }
+
+ return Status.OK_STATUS;
+ }
+ };
+ job.schedule();
+ }
+
+ public IRunnableWithProgress getLoadImageRunnable(final Runnable postRunnable){
+
final Display display = getLayoutComposite().getDisplay();
IRunnableWithProgress runnable = new IRunnableWithProgress(){
@Override
public void run(IProgressMonitor monitor) {
- try {
- monitor.beginTask("Loading: " + getImageUri(), IProgressMonitor.UNKNOWN);
- InputStream imageStream = UriUtils.getInputStream(imageUri);
-
- image = new Image(Display.getCurrent(), imageStream);
-
- // redraw the image container
- display.asyncExec(new Runnable(){
- @Override
- public void run() {
- if(! getLayoutComposite().isDisposed()){
- Event untypedEvent = new Event();
- untypedEvent.widget = container;
- PaintEvent event = new PaintEvent(untypedEvent);
- event.gc = new GC(container);
- paintControl(event);
- getLayoutComposite().layout();
- }
+ monitor.beginTask("Loading: " + getImageUri(), IProgressMonitor.UNKNOWN);
+
+ // redraw the image container
+ display.asyncExec(new Runnable(){
+ @Override
+ public void run() {
+ if(! getLayoutComposite().isDisposed()){
+ Event untypedEvent = new Event();
+ untypedEvent.widget = container;
+ PaintEvent event = new PaintEvent(untypedEvent);
+ event.gc = new GC(container);
+ paintControl(event);
+ getLayoutComposite().layout();
}
- });
-
- // execute the external runnable
- if(postRunnable != null){
- display.asyncExec(postRunnable);
}
- monitor.done();
- }catch (Exception e) {
- StoreUtil.warn(getClass(), e.getMessage());
- }
- }
+ });
+
+ // execute the external runnable
+ if(postRunnable != null){
+ display.asyncExec(postRunnable);
+ }
+ monitor.done();
+ }
+
};
return runnable;
}
-
+
private void calculateImageBounds(){
Rectangle imageBounds = image.getBounds();
Rectangle containerBounds = container.getBounds();
/** {@inheritDoc} */
@Override
public void paintControl(PaintEvent e) {
+ TableWrapData layoutData = CdmFormFactory.FILL(2, 1);
+ Composite composite = (Composite) e.widget;
if(image != null){
calculateImageBounds();
- Composite composite = (Composite) e.widget;
- TableWrapData layoutData = CdmFormFactory.FILL(2, 1);
layoutData.heightHint = imageMaxBounds.height;
- composite.setLayoutData(layoutData);
e.gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, imageMaxBounds.width, imageMaxBounds.height);
- e.gc.dispose();
- }
+ }else{
+ layoutData.heightHint = 10;
+ e.gc.drawRectangle(0, 0, 0, 10);
+ }
+ composite.setLayoutData(layoutData);
+ e.gc.dispose();
}
+
}
super(formFactory, formElement);
this.conversation = conversation;
+ this.user = user;
Label label = formFactory.createLabel(getLayoutComposite(), null);
addControl(label);
@Override
public void addPages() {
CdmFormFactory formFactory = new CdmFormFactory(Display.getDefault());
+
+// if(CdmStore.getLoginManager().isAdmin()){
+//
+// }else{
+// }
passwordPage = new PasswordWizardPage(formFactory, getConversationHolder(), user);
- super.addPage(passwordPage);
+ addPage(passwordPage);
}
/* (non-Javadoc)
public boolean performFinish() {
ConversationHolder internalConversation = CdmStore.getLoginManager().getConversationHolder();
internalConversation.bind();
- CdmStore.getService(IUserService.class).changePassword(passwordPage.getOldPassword(), passwordPage.getNewPassword());
+ if(CdmStore.getLoginManager().isAdmin()){
+ CdmStore.getService(IUserService.class).changePasswordForUser(user.getUsername(), passwordPage.getNewPassword());
+ }else{
+ CdmStore.getService(IUserService.class).changePassword(passwordPage.getOldPassword(), passwordPage.getNewPassword());
+ }
internalConversation.commit();
conversation.bind();
return true;
*/
public void displayImage() {
URI imageUri = getWizard().getOpenUrlReferenceImageUri();
- imageElement.setImageUri(imageUri);
-
- IRunnableWithProgress runnable = imageElement.getLoadImageRunnable(new Runnable(){
- /* (non-Javadoc)
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run() {
- container.layout();
-
- configurePageBar();
- }
- });
-
try {
+ imageElement.initImageUri(imageUri);
+
+ IRunnableWithProgress runnable = imageElement.getLoadImageRunnable(new Runnable(){
+ /* (non-Javadoc)
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ container.layout();
+
+ configurePageBar();
+ }
+ });
+
getWizard().getContainer().run(true, false, runnable);
} catch (Exception e) {
StoreUtil.errorDialog("Could not load image", getClass(), e.getMessage() + ": " + imageUri , e);
import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.http.HttpException;
import org.eclipse.swt.events.SelectionListener;
-import eu.etaxonomy.cdm.api.service.IMediaService;
import eu.etaxonomy.cdm.common.media.ImageInfo;
import eu.etaxonomy.cdm.model.media.ImageFile;
-import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.forms.ImageElement;
import eu.etaxonomy.taxeditor.ui.forms.KeyValueViewerElement;
+import eu.etaxonomy.taxeditor.ui.forms.LabelElement;
import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractMediaRepresentationPartElement;
private KeyValueViewerElement element_keyValue;
private ImageElement element_image;
+ private LabelElement element_messages;
+ private Runnable postRunnable = new Runnable(){
+ public void run() {
+ StoreUtil.reflowDetailsViewer();
+ StoreUtil.reflowSupplementalViewer();
+ }
+ };
+
+
/**
* <p>Constructor for ImageFileElement.</p>
*
text_width = formFactory.createIntegerTextWithLabelElement(formElement, "Width", null, style);
text_width.setEnabled(false);
element_image = formFactory.createImageElement(formElement, null, style);
-
+ element_messages = formFactory.createLabel(formElement, "");
element_keyValue = formFactory.createKeyValueViewerElement(formElement, "Key", "Value", null);
}
@Override
public void setEntity(ImageFile entity) {
this.entity = entity;
- if(entity.getUri() != null){
- text_uri.setText(entity.getUri().toString());
- }
if(entity.getSize() != null){
text_size.setText(FileUtils.byteCountToDisplaySize(entity.getSize()));
}
text_height.setInteger(entity.getHeight());
text_width.setInteger(entity.getWidth());
-
- showImage(entity.getUri());
+ if(entity.getUri() != null){
+ text_uri.setText(entity.getUri().toString());
+ }
+ try {
+ showImage(entity.getUri());
+ element_messages.setText("");
+ } catch (Exception e) {
+ handleException(e);
+ }
}
- private void showImage(URI uri){
+ private void showImage(URI uri) throws IOException, HttpException{
+ element_image.initImageUri(uri);
+
+ element_image.loadImage(postRunnable );
+
+
if(uri == null){
return;
}
- try {
-
- try {
-
- ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 10000);
-
- text_size.setText(FileUtils.byteCountToDisplaySize(imageInfo.getLength()));
- // KLUDGE this is not save for very large files. I don't think we will handle such large files in the near future
- getEntity().setSize((int) imageInfo.getLength());
-
- text_height.setInteger(imageInfo.getHeight());
- getEntity().setHeight(imageInfo.getHeight());
-
- text_width.setInteger(imageInfo.getWidth());
- getEntity().setWidth(imageInfo.getWidth());
- element_keyValue.setInput(imageInfo.getMetaData());
-
- element_image.setImageUri(uri);
-
- element_image.loadImage(new Runnable(){
- public void run() {
- StoreUtil.reflowDetailsViewer();
- StoreUtil.reflowSupplementalViewer();
- }
- });
+
+ ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 10000);
- } catch (IOException e) {
- StoreUtil.error(getClass(), e);
- }
- } catch (Exception e) {
- StoreUtil.error(getClass(), "Image could not be shown: ", e);
- }
+ text_size.setText(FileUtils.byteCountToDisplaySize(imageInfo.getLength()));
+ // KLUDGE this is not save for very large files, because of the int cast. But then, I don't think we will handle such large files in the near future
+ getEntity().setSize((int) imageInfo.getLength());
+
+ text_height.setInteger(imageInfo.getHeight());
+ getEntity().setHeight(imageInfo.getHeight());
+
+ text_width.setInteger(imageInfo.getWidth());
+ getEntity().setWidth(imageInfo.getWidth());
+ element_keyValue.setInput(imageInfo.getMetaData());
+
+ element_messages.setText("");
}
/*
URI uri = StringUtils.isNotEmpty(uriString) ? new URI(uriString) : null;
getEntity().setUri(uri);
+
showImage(getEntity().getUri());
-
+
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
- } catch (URISyntaxException e) {
- StoreUtil.warningDialog("Could not parse URI", getClass(), e.getMessage());
- }
+ } catch (Exception e) {
+ handleException(e);
+ }
}
}
+
+ private void handleException(Exception e) {
+ element_messages.setText(e.getMessage());
+ element_image.unloadImage(postRunnable);
+ text_size.setText("");
+ text_height.setInteger(0);
+ text_width.setInteger(0);
+
+ element_image.loadImage(new Runnable(){
+ public void run() {
+ StoreUtil.reflowDetailsViewer();
+ StoreUtil.reflowSupplementalViewer();
+ }
+ });
+ }
}
*/
package eu.etaxonomy.taxeditor.ui.section.user;
+import eu.etaxonomy.cdm.api.service.IUserService;
import eu.etaxonomy.cdm.model.common.User;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
text_username = formFactory.createTextWithLabelElement(formElement,
"Username", entity.getUsername(), style);
- if (userIsAuthenticated()) {
+ if (userIsAuthenticated() || CdmStore.getLoginManager().isAdmin()) {
element_editPassword = formFactory.createEditPasswordElement(
formElement, "Change Password", getConversationHolder(),
entity, style);