import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
* @date Sep 21, 2015
*
*/
-public abstract class UriWithExceptionLabelElement <T> extends TextWithLabelElement {
+public abstract class AbstractUriWithExceptionLabelElement <T> extends TextWithLabelElement {
protected Label labelException;
- protected UriWithExceptionLabelElement(CdmFormFactory formFactory,
+ protected AbstractUriWithExceptionLabelElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, String labelString,
T initialObject, Integer textHeight, int style) {
super(formFactory, parentElement, false);
- //label
+ init(formFactory, labelString, initialObject, textHeight, style);
+ }
+
+ protected void init(CdmFormFactory formFactory, String labelString, T initialObject, Integer textHeight, int style) {
+ //label
initLabel(formFactory, labelString, false, getLayoutComposite());
//uri text
initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
//exceptionLabel
- initExceptionLabel(formFactory, initialObject);
- }
+ initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
+ }
- private void initExceptionLabel(CdmFormFactory formFactory, T initialObject) {
- labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP); //$NON-NLS-1$
+ protected void initExceptionLabel(Composite parent, CdmFormFactory formFactory, T initialObject) {
+ labelException = formFactory.createLabel(parent, "", SWT.WRAP); //$NON-NLS-1$
int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
- if(getLayoutComposite().getLayout() instanceof TableWrapLayout){
- numColumns = ((TableWrapLayout)getLayoutComposite().getLayout()).numColumns;
+ if(parent.getLayout() instanceof TableWrapLayout){
+ numColumns = ((TableWrapLayout)parent.getLayout()).numColumns;
}
labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
addControl(labelException);
public abstract void setParsedText(T object);
- public abstract T parseText();
+ protected abstract T getParsedText() throws Exception;
- protected void updateExceptionLabel(Exception e){
- if(e!=null){
- labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
- labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
- labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+e.getLocalizedMessage());
- }
- else{
+ public T parseText(){
+ try {
labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
labelException.setForeground(getPersistentBackground());
labelException.setText(""); //$NON-NLS-1$
+ return getParsedText();
+ } catch (Exception e) {
+ labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
+ labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+ labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+e.getLocalizedMessage());
+ return null;
}
}
* @date Sep 21, 2015
*
*/
-public class LsidWithExceptionLabelElement extends UriWithExceptionLabelElement<LSID> {
+public class LsidWithExceptionLabelElement extends AbstractUriWithExceptionLabelElement<LSID> {
protected LsidWithExceptionLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement,
String labelString, LSID initialObject, Integer textHeight, int style) {
* {@inheritDoc}
*/
@Override
- public LSID parseText() {
- try {
- updateExceptionLabel(null);
+ public LSID getParsedText() throws Exception {
return new LSID(super.getText());
- } catch (Exception e) {
- updateExceptionLabel(e);
- return null;
- }
}
}
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.forms.widgets.TableWrapLayout;
import eu.etaxonomy.taxeditor.Messages;
import eu.etaxonomy.taxeditor.model.ImageResources;
* @created Dec 20, 2010
* @version 1.0
*/
-public class UriWithLabelElement extends TextWithLabelElement {
+public class UriWithLabelElement extends AbstractUriWithExceptionLabelElement<URI> {
- private final Label labelException;
- private final Button btnOpenBrowser;
+ private Button btnOpenBrowser;
- protected UriWithLabelElement(CdmFormFactory formFactory,
- ICdmFormElement parentElement, String labelString,
- URI initialUri, Integer textHeight, int style) {
- super(formFactory, parentElement, false);
+ protected UriWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
+ URI initialObject, Integer textHeight, int style) {
+ super(formFactory, parentElement, labelString, initialObject, textHeight, style);
- //label
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void init(CdmFormFactory formFactory, String labelString, URI initialObject, Integer textHeight, int style) {
+
+ //label
initLabel(formFactory, labelString, false, getLayoutComposite());
//composite(uri + button)
initText(formFactory, null, textHeight, null, false, style, textAndButton);
//button
- btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
- btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
- btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
- btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
- String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
-
- URI uri = getUri();
- if(uri!=null){
- try {
+ btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
+ btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
+ btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
+ btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
+ String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
+
+ URI uri = parseText();
+ if(uri!=null){
+ try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(uri.toURL());
} catch (PartInitException pie) {
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
} catch (IllegalArgumentException iae) {
MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
}
- }
- else{
- MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
- }
- }
+ }
+ else{
+ MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
+ }
+ }
});
- btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
-
- labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP); //$NON-NLS-1$
- int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
- if(getLayoutComposite().getLayout() instanceof TableWrapLayout){
- numColumns = ((TableWrapLayout)getLayoutComposite().getLayout()).numColumns;
- }
- labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
- addControl(labelException);
- setUri(initialUri);
- }
+ btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
+
+ initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
+ }
- public void setUri(URI uri) {
- if(uri != null){
- super.setText(uri.toString());
- }
- }
- public URI getUri(){
- try {
- labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
- labelException.setForeground(getPersistentBackground());
- labelException.setText(""); //$NON-NLS-1$
- return new URI(super.getText());
- } catch (Exception e) {
- labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
- labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
- labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+e.getLocalizedMessage());
- return null;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setParsedText(URI object) {
+ if(object != null){
+ super.setText(object.toString());
}
- }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected URI getParsedText() throws Exception {
+ return new URI(super.getText());
+ }
}
public void handleEvent(Object eventSource) {
if(eventSource == text_uri){
try {
- URI uri = text_uri.getUri();
+ URI uri = text_uri.parseText();
getEntity().setUri(uri);
if(uri==null){
//buffer URI if parsing error occurred
public void handleEvent(Object eventSource){
if(eventSource==textUri){
textUri.setBackground(getPersistentBackground());
- URI uri = textUri.getUri();
+ URI uri = textUri.parseText();
singleMediaRepresentationPart.setUri(uri);
if(uri==null){
uriBuffer=textUri.getText();
}
textUri = formFactory.createUriWithLabelElement(parentFormElement, "Media URI", null, style);
URI uri = singleMediaRepresentationPart.getUri();
- textUri.setUri(uri);
+ textUri.setParsedText(uri);
//set buffered uri as text if uri had parsing problems in advanced view
if(uri==null && uriBuffer!=null){
textUri.setText(uriBuffer);
- textUri.getUri();
+ textUri.parseText();
}
textUri.getLayoutComposite().layout();
}
text_size.setText(FileUtils.byteCountToDisplaySize(entity.getSize()));
}
if(entity.getUri() != null){
- text_uri.setUri(entity.getUri());
+ text_uri.setParsedText(entity.getUri());
} else {
String uriBuffer = getParentMediaDetailElement().getUriBuffer();
if(uriBuffer!=null){
text_uri.setText(uriBuffer);
- text_uri.getUri();//just to update the error label
+ text_uri.parseText();//just to update the error label
}
}
}
@Override
public void handleEvent(Object eventSource) {
if(eventSource == text_uri){
- URI uri = text_uri.getUri();
+ URI uri = text_uri.parseText();
getEntity().setUri(uri);
if(uri==null){
//buffer URI if parsing error occurred
@Override
public void handleEvent(Object eventSource) {
if(eventSource == protologueUriText && protologueUriText.getText()!=null){
- mediaRepresentationPart.setUri(protologueUriText.getUri());
+ mediaRepresentationPart.setUri(protologueUriText.parseText());
}
}
getEntity().setGeneticAccessionNumber(textGeneticAccessNo.getText());
if(textGeneticAccessNo.getText()!=null && !textGeneticAccessNo.getText().isEmpty()){
try {
- textNCBIUri.setUri(getEntity().getGenBankUri());
- textENAUri.setUri(getEntity().getEmblUri());
- textDDBJUri.setUri(getEntity().getDdbjUri());
+ textNCBIUri.setParsedText(getEntity().getGenBankUri());
+ textENAUri.setParsedText(getEntity().getEmblUri());
+ textDDBJUri.setParsedText(getEntity().getDdbjUri());
} catch (URISyntaxException e) {
textGeneticAccessNo.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
}
getEntity().setBoldProcessId(textBoldProcessID.getText());
if(textBoldProcessID.getText()!=null && !textBoldProcessID.getText().isEmpty()){
try {
- textBoldUri.setUri(getEntity().getBoldUri());
+ textBoldUri.setParsedText(getEntity().getBoldUri());
} catch (URISyntaxException e) {
textBoldProcessID.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
}
getEntity().setAbbrevTitle(text_abbrevTitle.getText());
toggleableAbbrevCache.setText(text_abbrevTitle.getText());
} else if (eventSource == text_uri) {
- getEntity().setUri(text_uri.getUri());
+ getEntity().setUri(text_uri.parseText());
} else if (eventSource == text_volume) {
getEntity().setVolume(text_volume.getText());
}
} else if (eventSource == text_description) {\r
getEntity().getRepresentation(Language.getDefaultLanguage()).setText(text_description.getText());\r
} else if (eventSource == uri_uri) {\r
- getEntity().setUri(uri_uri.getUri());\r
+ getEntity().setUri(uri_uri.parseText());\r
} else if (eventSource == text_abbreviatedLabel) {\r
getEntity().getRepresentation(Language.getDefaultLanguage()).setAbbreviatedLabel(text_abbreviatedLabel.getText());\r
} else if (eventSource == timePeriod_validPeriod) {\r
handleRepresentation(eventSource);\r
\r
if (eventSource == uri_uri) {\r
- getEntity().setUri(uri_uri.getUri());\r
+ getEntity().setUri(uri_uri.parseText());\r
} else if (eventSource == uri_uriTermSource) {\r
- getEntity().setTermSourceUri(uri_uriTermSource.getUri());\r
+ getEntity().setTermSourceUri(uri_uriTermSource.parseText());\r
}\r
}\r
\r