|
From: <vh...@us...> - 2013-03-27 19:50:23
|
Revision: 16170
http://unicore.svn.sourceforge.net/unicore/?rev=16170&view=rev
Author: vhuber
Date: 2013-03-27 19:50:14 +0000 (Wed, 27 Mar 2013)
Log Message:
-----------
New feature:
+ Added a button for upload of local files to workspace in the Browse Data View
Changes:
+ Double click on file in DataEndpoint opens the file content in the browser instead of in the text editor (make possible to view images and other then .txt file formats).
+ The method removeWhiteSpaces(String filename) is now static method in the StringUtils class
Modified Paths:
--------------
unicore-portal/trunk/core/src/main/java/eu/unicore/portal/core/utils/StringUtils.java
unicore-portal/trunk/grid.core/src/main/java/eu/unicore/portal/grid/core/utils/UnicoreStorageTools.java
unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/browser/U6DataEndpointViewer.java
unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/jobs/params/InputFileRow.java
unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/views/DataView.java
unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/viewers/DataEndpointViewer.java
unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/views/UserProfileView.java
Modified: unicore-portal/trunk/core/src/main/java/eu/unicore/portal/core/utils/StringUtils.java
===================================================================
--- unicore-portal/trunk/core/src/main/java/eu/unicore/portal/core/utils/StringUtils.java 2013-03-27 17:30:29 UTC (rev 16169)
+++ unicore-portal/trunk/core/src/main/java/eu/unicore/portal/core/utils/StringUtils.java 2013-03-27 19:50:14 UTC (rev 16170)
@@ -80,4 +80,8 @@
}
return suffix;
}
+
+ public static String removeWhiteSpaces(String filename) {
+ return filename.replaceAll("\\s+", "_");
+ }
}
\ No newline at end of file
Modified: unicore-portal/trunk/grid.core/src/main/java/eu/unicore/portal/grid/core/utils/UnicoreStorageTools.java
===================================================================
--- unicore-portal/trunk/grid.core/src/main/java/eu/unicore/portal/grid/core/utils/UnicoreStorageTools.java 2013-03-27 17:30:29 UTC (rev 16169)
+++ unicore-portal/trunk/grid.core/src/main/java/eu/unicore/portal/grid/core/utils/UnicoreStorageTools.java 2013-03-27 19:50:14 UTC (rev 16170)
@@ -742,5 +742,6 @@
+
}
Modified: unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/browser/U6DataEndpointViewer.java
===================================================================
--- unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/browser/U6DataEndpointViewer.java 2013-03-27 17:30:29 UTC (rev 16169)
+++ unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/browser/U6DataEndpointViewer.java 2013-03-27 19:50:14 UTC (rev 16170)
@@ -1,22 +1,30 @@
package eu.unicore.portal.grid.ui.browser;
+import java.io.OutputStream;
+
+import org.apache.commons.vfs2.FileObject;
import org.apache.log4j.Logger;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Upload.FinishedEvent;
+import com.vaadin.ui.Upload.FinishedListener;
+import com.vaadin.ui.Upload.Receiver;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
+import com.vaadin.ui.Upload;
import eu.unicore.portal.core.GlobalState;
import eu.unicore.portal.core.Session;
import eu.unicore.portal.core.data.DataEndpoint;
import eu.unicore.portal.core.threads.BackgroundWorker;
import eu.unicore.portal.core.threads.IProgressMonitor;
+import eu.unicore.portal.core.utils.StringUtils;
import eu.unicore.portal.grid.core.data.u6.U6DataEndpoint;
import eu.unicore.portal.grid.core.nodes.Node;
import eu.unicore.portal.grid.core.nodes.u6.StorageNode;
@@ -25,233 +33,276 @@
import eu.unicore.portal.ui.i18n.UII18N;
import eu.unicore.portal.ui.viewers.DataEndpointViewer;
+/**
+ *
+ * @author v.huber
+ *
+ */
+public class U6DataEndpointViewer extends DataEndpointViewer {
+ private static final long serialVersionUID = 1L;
+ private static final Logger logger = Logger
+ .getLogger(U6DataEndpointViewer.class);
-
-
-public class U6DataEndpointViewer extends DataEndpointViewer
-{
- private static final long serialVersionUID = 1L;
- private static final Logger logger = Logger.getLogger(U6DataEndpointViewer.class);
-
private ComboBox storageType;
private ComboBox protocolComboBox;
private TextField storageTextField;
private Button chooseStorageButton;
- StorageChooser storageChooser;
+ private StorageChooser storageChooser;
+ private Upload upload;
- enum StorageType {
- WORKSPACE("Workspace"), //$NON-NLS-1$
- UNICORE_STORAGE("Storage"); //$NON-NLS-1$
+ enum StorageType {
+ WORKSPACE("Workspace"), //$NON-NLS-1$
+ UNICORE_STORAGE("Storage"); //$NON-NLS-1$
- private String name;
+ private String name;
- private StorageType(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
+ private StorageType(String name) {
+ this.name = name;
}
- public U6DataEndpointViewer() {
- this(null);
+ @Override
+ public String toString() {
+ return name;
}
+ }
- public U6DataEndpointViewer(DataEndpoint endpoint) {
- super(endpoint);
+ public U6DataEndpointViewer() {
+ this(null);
+ }
- addComponent(getProtocolChooser());
+ public U6DataEndpointViewer(DataEndpoint endpoint) {
+ super(endpoint);
- if (endpoint != null) {
- showDataEndpoint(endpoint);
- }
- }
+ addComponent(getProtocolChooser());
- protected void createMenuBar() {
- super.createMenuBar();
- Component storageSourceChooser = getStorageSourceChooser();
- addComponent(storageSourceChooser);
+ if (endpoint != null) {
+ showDataEndpoint(endpoint);
}
+ }
- private Component getProtocolChooser() {
- protocolComboBox = new ComboBox();
- protocolComboBox.setImmediate(true);
- HorizontalLayout layout = new HorizontalLayout();
- layout.addComponent(new Label(GlobalState.getMessage(GridUII18N.ID, "U6DataEndpointViewer.FTP"))); //$NON-NLS-1$
- layout.addComponent(protocolComboBox);
- return layout;
- }
-
-
- private Component getStorageSourceChooser() {
- storageTextField = new TextField();
- storageTextField.setImmediate(true);
- storageTextField.setWidth(200, Unit.PIXELS);
+ protected void createMenuBar() {
+ super.createMenuBar();
+ getMenuBar().addComponent(createUploadPopup());
+ Component storageSourceChooser = getStorageSourceChooser();
+ addComponent(storageSourceChooser);
+ }
- storageType = new ComboBox();
- storageType.addItem(StorageType.WORKSPACE);
- storageType.addItem(StorageType.UNICORE_STORAGE);
- storageType.setValue(StorageType.UNICORE_STORAGE);
- storageType.setWidth(100, Unit.PIXELS);
- storageType.addValueChangeListener(new Property.ValueChangeListener() {
+ private Component getProtocolChooser() {
+ protocolComboBox = new ComboBox();
+ protocolComboBox.setImmediate(true);
+ HorizontalLayout layout = new HorizontalLayout();
+ layout.addComponent(new Label(GlobalState.getMessage(GridUII18N.ID,
+ "U6DataEndpointViewer.FTP"))); //$NON-NLS-1$
+ layout.addComponent(protocolComboBox);
+ return layout;
+ }
+
+ private Component getStorageSourceChooser() {
+ storageTextField = new TextField();
+ storageTextField.setImmediate(true);
+ storageTextField.setWidth(200, Unit.PIXELS);
+
+ storageType = new ComboBox();
+ storageType.addItem(StorageType.WORKSPACE);
+ storageType.addItem(StorageType.UNICORE_STORAGE);
+ storageType.setValue(StorageType.UNICORE_STORAGE);
+ storageType.setWidth(100, Unit.PIXELS);
+ storageType.addValueChangeListener(new Property.ValueChangeListener() {
private static final long serialVersionUID = 1L;
@Override
- public void valueChange(final ValueChangeEvent event)
- {
- Object o = storageType.getValue();
- if (o == StorageType.WORKSPACE)
- {
- showWorkspace();
- }
- else
- {
- showStorageChooser();
- }
- }
+ public void valueChange(final ValueChangeEvent event) {
+ Object o = storageType.getValue();
+ if (o == StorageType.WORKSPACE) {
+ showWorkspace();
+ } else {
+ showStorageChooser();
+ }
+ }
});
- storageType.setImmediate(true);
+ storageType.setImmediate(true);
- chooseStorageButton = new Button(GlobalState.getMessage(GridUII18N.ID, "U6DataEndpointViewer.choose"), //$NON-NLS-1$
- new Button.ClickListener() {
- private static final long serialVersionUID = 1L;
+ chooseStorageButton = new Button(GlobalState.getMessage(GridUII18N.ID,
+ "U6DataEndpointViewer.choose"), //$NON-NLS-1$
+ new Button.ClickListener() {
+ private static final long serialVersionUID = 1L;
- @Override
- public void buttonClick(ClickEvent event) {
- showStorageChooser();
- }
- });
- chooseStorageButton.setImmediate(true);
+ @Override
+ public void buttonClick(ClickEvent event) {
+ showStorageChooser();
+ }
+ });
+ chooseStorageButton.setImmediate(true);
- HorizontalLayout layout = new HorizontalLayout();
- layout.addComponent(storageTextField);
- layout.addComponent(storageType);
- layout.addComponent(chooseStorageButton);
- return layout;
- }
+ HorizontalLayout layout = new HorizontalLayout();
+ layout.addComponent(storageTextField);
+ layout.addComponent(storageType);
+ layout.addComponent(chooseStorageButton);
+ return layout;
+ }
-
- public void setSourceSelectable(boolean b)
- {
- storageType.setEnabled(b);
+ public void setSourceSelectable(boolean b) {
+ storageType.setEnabled(b);
}
-
-
- public void showWorkspace()
- {
- if (storageType.getValue() != StorageType.WORKSPACE)
- {
- storageType.setValue(StorageType.WORKSPACE);
- }
- showDataEndpoint(getWorkspaceLocation());
+
+ public void showWorkspace() {
+ if (storageType.getValue() != StorageType.WORKSPACE) {
+ storageType.setValue(StorageType.WORKSPACE);
+ }
+ showDataEndpoint(getWorkspaceLocation());
+ upload.setEnabled(true);
}
-
- public void showStorageChooser()
- {
- if (storageChooser == null)
- {
- storageChooser = new StorageChooser(GlobalState.getMessage(GridUII18N.ID, "U6DataEndpointViewer.available"), //$NON-NLS-1$
- new StorageChooser.StorageChooserCallback() {
- @Override
- public void response(Node node, boolean ok) {
- if (ok) {
- if (node != null && node instanceof StorageNode)
- {
- StorageNode n = (StorageNode)node;
- U6DataEndpoint ep = new U6DataEndpoint(n.getURI().toString());
- if (storageType.getValue() != StorageType.UNICORE_STORAGE)
- {
- storageType.setValue(StorageType.UNICORE_STORAGE);
- }
- showDataEndpoint(ep);
- }
- else
- {
- logger.warn(GlobalState.getMessage(UII18N.ID, "VFSAction.select_resource")); //$NON-NLS-1$
- }
- }
- }
- });
+
+ public void showStorageChooser() {
+ if (storageChooser == null) {
+ storageChooser = new StorageChooser(GlobalState.getMessage(
+ GridUII18N.ID, "U6DataEndpointViewer.available"), //$NON-NLS-1$
+ new StorageChooser.StorageChooserCallback() {
+ @Override
+ public void response(Node node, boolean ok) {
+ if (ok) {
+ if (node != null && node instanceof StorageNode) {
+ StorageNode n = (StorageNode) node;
+ U6DataEndpoint ep = new U6DataEndpoint(n
+ .getURI().toString());
+ if (storageType.getValue() != StorageType.UNICORE_STORAGE) {
+ storageType
+ .setValue(StorageType.UNICORE_STORAGE);
+ upload.setEnabled(false);
+ }
+ showDataEndpoint(ep);
+ } else {
+ logger.warn(GlobalState.getMessage(
+ UII18N.ID,
+ "VFSAction.select_resource")); //$NON-NLS-1$
+ }
+ }
+ }
+ });
PortalApplication.getCurrent().addWindow(storageChooser);
- }
- else
- {
+ } else {
storageChooser.refresh();
storageChooser.setVisible(true);
}
-
- }
-
- public void showDataEndpoint(final DataEndpoint endpoint)
- {
- BackgroundWorker j = new BackgroundWorker(GlobalState.getMessage(GridUII18N.ID, "U6DataEndpointViewer.browsing")) { //$NON-NLS-1$
+ }
- @Override
- protected void work(IProgressMonitor progress) {
- // TODO check if we can create the new model content here
- }
+ public void showDataEndpoint(final DataEndpoint endpoint) {
+ BackgroundWorker j = new BackgroundWorker(GlobalState.getMessage(
+ GridUII18N.ID, "U6DataEndpointViewer.browsing")) { //$NON-NLS-1$
- @Override
- protected void updateUI() {
- try
- {
- setEndpoint(endpoint);
- String uri = endpoint.getVFSRoot().getURL().toString();
- storageTextField.setValue(uri);
- updateProtocols();
- if (storageChooser != null && storageChooser.isVisible())
- {
- storageChooser.setVisible(false);
- }
- }
- catch(Exception e)
- {
- logger.error("Failure browsing storage: "+e.getLocalizedMessage(), e); //$NON-NLS-1$
- }
+ @Override
+ protected void work(IProgressMonitor progress) {
+ // TODO check if we can create the new model content here
+ }
+
+ @Override
+ protected void updateUI() {
+ try {
+ setEndpoint(endpoint);
+ String uri = endpoint.getVFSRoot().getURL().toString();
+ storageTextField.setValue(uri);
+ updateProtocols();
+ if (storageChooser != null && storageChooser.isVisible()) {
+ storageChooser.setVisible(false);
+ }
+ } catch (Exception e) {
+ logger.error(
+ "Failure browsing storage: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
}
+ }
- };
- j.schedule();
+ };
+ j.schedule();
+ }
+
+ public DataEndpoint getWorkspaceLocation() {
+ return Session.getCurrent().getUser().getWorkspaceLocation();
+ }
+
+ private void updateProtocols() {
+ String[] protocols = getEndpoint().getSendProtocols();
+ protocolComboBox.removeAllItems();
+ for (String protocol : protocols) {
+ protocolComboBox.addItem(protocol);
}
-
-
- public DataEndpoint getWorkspaceLocation() {
- return Session.getCurrent().getUser().getWorkspaceLocation();
+ if (protocols.length > 0) {
+ protocolComboBox.setValue(protocols[0]);
}
-
-
- private void updateProtocols() {
- String[] protocols = getEndpoint().getSendProtocols();
- protocolComboBox.removeAllItems();
- for (String protocol : protocols)
- {
- protocolComboBox.addItem(protocol);
+ }
+
+ public String[] getSupportedProtocols() {
+ return (getEndpoint() != null) ? getEndpoint().getSendProtocols()
+ : null;
+ }
+
+ public boolean isSupportedProtocol(String protocol) {
+ return getProtocolComboBox().containsId(protocol);
+ }
+
+ public ComboBox getProtocolComboBox() {
+ return protocolComboBox;
+ }
+
+ public String getSelectedProtocol() {
+ Object o = protocolComboBox.getValue();
+ return o != null ? (String) o : null;
+ }
+
+ protected Upload createUploadPopup() {
+ upload = new Upload();
+ upload.setButtonCaption("");
+ upload.setStyleName("my-upload-button");
+ upload.setDescription(GlobalState.getMessage(UII18N.ID,
+ "VFSAction.upload_file"));
+ upload.setImmediate(true);
+ upload.setEnabled(false);
+ upload.addFinishedListener(new FinishedListener() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void uploadFinished(FinishedEvent event) {
+ try {
+ FileObject uploadDir = getCurrentDir();
+ String fn = event.getFilename();
+ FileObject file = uploadDir.resolveFile(fn);
+ if (file.exists()) {
+ refresh();
+ } else {
+ throw new Exception("File does not exist.");
+ }
+ } catch (Exception e) {
+ logger.warn(
+ "Unable to refer to file: "
+ + e.getLocalizedMessage(), e);
+ }
}
- if (protocols.length > 0)
- {
- protocolComboBox.setValue(protocols[0]);
+ });
+
+ Receiver r = new Receiver() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public OutputStream receiveUpload(String filename, String mimeType) {
+ try {
+ FileObject uploadDir = getCurrentDir();
+ String fn = StringUtils.removeWhiteSpaces(filename);
+ FileObject file = uploadDir.resolveFile(fn);
+ file.createFile();
+ return file.getContent().getOutputStream();
+ } catch (Exception e) {
+ logger.warn(
+ "Failure uploading file: "
+ + e.getLocalizedMessage(), e);
+ return null;
+ }
+
}
- }
-
-
- public String[] getSupportedProtocols() {
- return (getEndpoint() != null) ? getEndpoint().getSendProtocols() : null;
- }
-
- public boolean isSupportedProtocol(String protocol) {
- return getProtocolComboBox().containsId(protocol);
- }
-
- public ComboBox getProtocolComboBox() {
- return protocolComboBox;
- }
-
- public String getSelectedProtocol() {
- Object o = protocolComboBox.getValue();
- return o != null ? (String)o : null;
- }
-
+ };
+ upload.setReceiver(r);
+ return upload;
+ }
+
}
\ No newline at end of file
Modified: unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/jobs/params/InputFileRow.java
===================================================================
--- unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/jobs/params/InputFileRow.java 2013-03-27 17:30:29 UTC (rev 16169)
+++ unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/jobs/params/InputFileRow.java 2013-03-27 19:50:14 UTC (rev 16170)
@@ -34,6 +34,7 @@
import com.vaadin.ui.Upload.FinishedListener;
import com.vaadin.ui.Upload.Receiver;
+import eu.unicore.portal.core.utils.StringUtils;
import eu.unicore.portal.core.GlobalState;
import eu.unicore.portal.grid.core.jobs.ComputeTaskParameterModel;
import eu.unicore.portal.grid.core.params.FileParameterMetaData;
@@ -197,7 +198,7 @@
if (fname == null) {
return;
}
- fname = removeWhiteSpaces(fname);
+ fname = StringUtils.removeWhiteSpaces(fname);
// Prevent from recursion without a bottom
if (fname.equals(filename) || (fname + ".txt").equals(filename)) { //$NON-NLS-1$
setSourceValue(filename);
@@ -311,7 +312,7 @@
return;
}
- filename = removeWhiteSpaces(filename);
+ filename = StringUtils.removeWhiteSpaces(filename);
if (filename.length() == 0 || isValidFilename(filename) == false) {
return;
}
@@ -364,8 +365,8 @@
@Override
public void uploadFinished(FinishedEvent event) {
try {
- FileObject file = inputDir.resolveFile(removeWhiteSpaces(event.getFilename()));
- filename = removeWhiteSpaces(event.getFilename());
+ FileObject file = inputDir.resolveFile(StringUtils.removeWhiteSpaces(event.getFilename()));
+ filename = StringUtils.removeWhiteSpaces(event.getFilename());
update(file);
} catch (Exception e) {
logger.warn("Unable to refer to file: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
@@ -382,7 +383,7 @@
{
try
{
- filename = removeWhiteSpaces(filename);
+ filename = StringUtils.removeWhiteSpaces(filename);
FileObject file = inputDir.resolveFile(filename);
file.createFile();
return file.getContent().getOutputStream();
@@ -424,10 +425,6 @@
protected void setSourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
}
-
- private String removeWhiteSpaces(String filename){
- return filename.replaceAll("\\s+", "_"); //$NON-NLS-1$ //$NON-NLS-2$
- }
private boolean isValidFilename(String fname){
String regex = "^[-_.,A-Za-z0-9]*"; //$NON-NLS-1$
Modified: unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/views/DataView.java
===================================================================
--- unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/views/DataView.java 2013-03-27 17:30:29 UTC (rev 16169)
+++ unicore-portal/trunk/grid.ui/src/main/java/eu/unicore/portal/grid/ui/views/DataView.java 2013-03-27 19:50:14 UTC (rev 16170)
@@ -43,14 +43,18 @@
private Button sendButton;
private Button receiveButton;
+
public DataView() {
- viewer1 = new U6DataEndpointViewer();
+
+ viewer1 = new U6DataEndpointViewer();
viewer1.setMargin(new MarginInfo(true, true, true, false));
- viewer1.getPanel().setWidth(450f, Unit.PIXELS);
+ viewer1.getComponent().setWidth(450f, Unit.PIXELS);
viewer1.showWorkspace();
+
viewer2 = new U6DataEndpointViewer();
viewer2.setMargin(new MarginInfo(true, false, true, true));
- viewer2.getPanel().setWidth(450f, Unit.PIXELS);
+ viewer2.getComponent().setWidth(450f, Unit.PIXELS);
+
final ComboBox cb1 = viewer1.getProtocolComboBox();
ComboBox cb2 = viewer2.getProtocolComboBox();
@@ -138,6 +142,7 @@
}
}
+
class SelectionListener implements Property.ValueChangeListener {
private static final long serialVersionUID = 1L;
@@ -161,7 +166,6 @@
}
}
-
}
}
\ No newline at end of file
Modified: unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/viewers/DataEndpointViewer.java
===================================================================
--- unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/viewers/DataEndpointViewer.java 2013-03-27 17:30:29 UTC (rev 16169)
+++ unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/viewers/DataEndpointViewer.java 2013-03-27 19:50:14 UTC (rev 16170)
@@ -17,13 +17,14 @@
import org.apache.log4j.Logger;
import com.vaadin.data.Container.Hierarchical;
-import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.HierarchicalContainer;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
+import com.vaadin.server.Page;
import com.vaadin.shared.ui.BorderStyle;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.Button;
@@ -85,8 +86,10 @@
private Hierarchical container;
private FileName workingDir = null;
private VFSActionHandler actionHandler;
+ private HorizontalLayout menuBar;
+
public DataEndpointViewer(final DataEndpoint endpoint)
{
container = createDataContainer();
@@ -143,9 +146,10 @@
public Component getComponent()
{
- return this;
+ return panel;
}
+
public Table getTable()
{
return table;
@@ -371,7 +375,8 @@
}
else if (FileType.FILE.equals(clicked.getType()))
{
- VFSUtils.openFileEditor(clicked);
+ VFSFileResource r = new VFSFileResource(clicked);
+ Page.getCurrent().open(r, "_blank", 600, 500, BorderStyle.DEFAULT);
}
} catch (Exception e)
{
@@ -386,9 +391,9 @@
* Creates the menu bar at the top of the window
*/
protected void createMenuBar() {
- HorizontalLayout menubar = new HorizontalLayout();
- menubar.setSpacing(true);
- menubar.setMargin(new MarginInfo(false, false, true, false));
+ menuBar = new HorizontalLayout();
+ menuBar.setSpacing(true);
+ menuBar.setMargin(new MarginInfo(false, false, true, false));
// Home button
Button homeButton = new VFSFileButton(VFSAction.ACTION_HOME, new Button.ClickListener()
@@ -491,14 +496,14 @@
}
});
- menubar.addComponent(homeButton);
- menubar.addComponent(newFolderButton);
- menubar.addComponent(newFileButton);
- menubar.addComponent(refreshButton);
- menubar.addComponent(deleteButton);
- menubar.addComponent(selectAll);
+ menuBar.addComponent(homeButton);
+ menuBar.addComponent(newFolderButton);
+ menuBar.addComponent(newFileButton);
+ menuBar.addComponent(refreshButton);
+ menuBar.addComponent(deleteButton);
+ menuBar.addComponent(selectAll);
- addComponent(menubar);
+ addComponent(menuBar);
}
@@ -563,12 +568,20 @@
return container;
}
+
+
public FileName getWorkingDir()
{
return workingDir;
}
+
+ protected HorizontalLayout getMenuBar()
+ {
+ return menuBar;
+ }
- public Panel getPanel() {
- return panel;
+ protected void setMenuBar(HorizontalLayout menuBar)
+ {
+ this.menuBar = menuBar;
}
}
Modified: unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/views/UserProfileView.java
===================================================================
--- unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/views/UserProfileView.java 2013-03-27 17:30:29 UTC (rev 16169)
+++ unicore-portal/trunk/ui/src/main/java/eu/unicore/portal/ui/views/UserProfileView.java 2013-03-27 19:50:14 UTC (rev 16170)
@@ -29,6 +29,7 @@
import eu.unicore.portal.core.User;
import eu.unicore.portal.core.User.Type;
import eu.unicore.portal.core.data.DataEndpoint;
+import eu.unicore.portal.core.utils.StringUtils;
import eu.unicore.portal.ui.Styles;
import eu.unicore.portal.ui.etd.ETDUploadComponent;
import eu.unicore.portal.ui.i18n.UII18N;
@@ -38,15 +39,16 @@
/**
*
* @author v.huber
- *
+ *
*/
-public class UserProfileView extends AbstractView {
+public class UserProfileView extends AbstractView
+{
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(UserProfileView.class);
public static final String VIEW_ID = "eu.unicore.portal.ui.views.UserProfileView"; //$NON-NLS-1$
-
+
private User user;
private ComponentContainer panel;
private Upload upload;
@@ -54,31 +56,37 @@
private Panel imagePanel;
private UserImageAttribute userImageAttr;
- public UserProfileView()
+
+ public UserProfileView()
{
user = Session.getCurrent().getUser();
}
- public void setVisible(boolean visible)
+
+ public void setVisible(boolean visible)
{
super.setVisible(visible);
- if (visible && panel == null) {
+ if (visible && panel == null)
+ {
createPanel();
}
}
- protected void createPanel()
+
+ protected void createPanel()
{
panel = new GridLayout();
panel.setWidth("400px"); //$NON-NLS-1$
- Label header = new Label(GlobalState.getMessage(UII18N.ID, "UserProfileView.profile")); //$NON-NLS-1$
+ Label header = new Label(GlobalState.getMessage(UII18N.ID,
+ "UserProfileView.profile")); //$NON-NLS-1$
header.addStyleName(Styles.CAPTION2);
panel.addComponent(header);
-
+
userImageAttr = user.getAttribute(UserImageAttribute.class);
- Embedded image = (userImageAttr != null) ? userImageAttr.getImage() : UserImageAttribute.getDefaultImage();
- upload = createUploadImagePopup();
+ Embedded image = (userImageAttr != null) ? userImageAttr.getImage()
+ : UserImageAttribute.getDefaultImage();
+ upload = createUploadImagePopup();
imagePanel = new Panel();
imagePanel.setContent(image);
HorizontalLayout hl = new HorizontalLayout();
@@ -86,20 +94,24 @@
hl.addComponent(upload);
hl.setComponentAlignment(upload, Alignment.BOTTOM_RIGHT);
panel.addComponent(hl);
-
+
FormLayout profileForm = new FormLayout();
- profileForm.setSizeUndefined(); // Make the FormLayout shrink to its contents
-
- final TextField userNameField = new TextField(GlobalState.getMessage(UII18N.ID, "UserProfileView.username")); //$NON-NLS-1$
+ profileForm.setSizeUndefined(); // allow the FormLayout to shrink
+
+ final TextField userNameField = new TextField(GlobalState.getMessage(
+ UII18N.ID, "UserProfileView.username")); //$NON-NLS-1$
userNameField.setValue(user.getUsername());
profileForm.addComponent(userNameField);
-
- final TextField emailField = new TextField(GlobalState.getMessage(UII18N.ID, "UserProfileView.email")); //$NON-NLS-1$
+
+ final TextField emailField = new TextField(GlobalState.getMessage(
+ UII18N.ID, "UserProfileView.email")); //$NON-NLS-1$
emailField.setNullRepresentation("");
emailField.setValue(user.getEMail());
profileForm.addComponent(emailField);
- final TextField organisationField = new TextField(GlobalState.getMessage(UII18N.ID, "UserProfileView.organisation")); //$NON-NLS-1$
+ final TextField organisationField = new TextField(
+ GlobalState.getMessage(UII18N.ID,
+ "UserProfileView.organisation")); //$NON-NLS-1$
organisationField.setNullRepresentation("");
organisationField.setValue(user.getOrganisation());
profileForm.addComponent(organisationField);
@@ -111,23 +123,24 @@
panel.addComponent(profileForm);
-
- if("TLS".equals(user.getAuthenticationSourceType())){ //$NON-NLS-1$
- ETDUploadComponent etd=new ETDUploadComponent();
+ if ("TLS".equals(user.getAuthenticationSourceType())) { //$NON-NLS-1$
+ ETDUploadComponent etd = new ETDUploadComponent();
panel.addComponent(etd);
etd.start();
}
-
- if(user.getType()!=Type.demo){
-
- Button submit = new Button(GlobalState.getMessage(UII18N.ID, "UserProfileView.save")); //$NON-NLS-1$
+
+ if (user.getType() != Type.demo)
+ {
+ Button submit = new Button(GlobalState.getMessage(UII18N.ID,
+ "UserProfileView.save")); //$NON-NLS-1$
submit.setStyleName(BaseTheme.BUTTON_LINK); //$NON-NLS-1$
- submit.addClickListener(new Button.ClickListener() {
-
+ submit.addClickListener(new Button.ClickListener()
+ {
private static final long serialVersionUID = 1L;
@Override
- public void buttonClick(ClickEvent event) {
+ public void buttonClick(ClickEvent event)
+ {
user.setUsername(userNameField.getValue());
user.setEMail(emailField.getValue());
user.setOrganisation(organisationField.getValue());
@@ -139,43 +152,58 @@
}
addComponent(panel);
-
+
}
- protected void saveUser()
+
+ protected void saveUser()
{
- try {
+ try
+ {
user.save();
- } catch (Exception ex) {
+ } catch (Exception ex)
+ {
logger.error("Can't persist updated User object", ex); //$NON-NLS-1$
}
}
-
-
- protected Upload createUploadImagePopup()
+
+
+ protected Upload createUploadImagePopup()
{
upload = new Upload();
upload.setButtonCaption("");
upload.setStyleName("my-upload-button");
- upload.setDescription(GlobalState.getMessage(UII18N.ID, "VFSAction.upload_file"));
+ upload.setDescription(GlobalState.getMessage(UII18N.ID,
+ "VFSAction.upload_file"));
upload.setImmediate(true);
upload.addFinishedListener(new FinishedListener() {
-
private static final long serialVersionUID = 1L;
@Override
- public void uploadFinished(FinishedEvent event) {
- try {
- FileObject file = uploadDir.resolveFile(removeWhiteSpaces(event.getFilename()));
- String fn = file.getName().getPath();
- updateUserImage(fn);
- } catch (Exception e) {
- logger.warn("Unable to refer to file: " + e.getLocalizedMessage(), e);
+ public void uploadFinished(FinishedEvent event)
+ {
+ try
+ {
+ String fn = event.getFilename();
+ FileObject file = uploadDir.resolveFile(event.getFilename());
+ if (file.exists())
+ {
+ updateUserImage(fn);
+ } else
+ {
+ throw new Exception("File does not exist");
+ }
+ } catch (Exception e)
+ {
+ logger.warn(
+ "Unable to refer to file: "
+ + e.getLocalizedMessage(), e);
}
}
});
- Receiver r = new Receiver() {
+ Receiver r = new Receiver()
+ {
private static final long serialVersionUID = 1L;
@@ -184,7 +212,7 @@
{
try
{
- String fn = removeWhiteSpaces(filename);
+ String fn = StringUtils.removeWhiteSpaces(filename);
if (uploadDir == null)
{
uploadDir = getImageUploadDirecory();
@@ -194,7 +222,9 @@
return file.getContent().getOutputStream();
} catch (Exception e)
{
- logger.warn("Unable to upload file: "+e.getLocalizedMessage(),e);
+ logger.warn(
+ "Unable to upload file: " + e.getLocalizedMessage(),
+ e);
return null;
}
@@ -203,23 +233,26 @@
upload.setReceiver(r);
return upload;
}
-
- public FileObject getImageUploadDirecory() throws FileSystemException, IOException {
- DataEndpoint workspace = Session.getCurrent().getUser().getWorkspaceLocation();
- return workspace.getVFSRoot().resolveFile(UserImageAttribute.WORKSPACE_USER_IMAGE_FOLDER);
+
+
+ public FileObject getImageUploadDirecory() throws FileSystemException,
+ IOException
+ {
+ DataEndpoint workspace = Session.getCurrent().getUser()
+ .getWorkspaceLocation();
+ return workspace.getVFSRoot().resolveFile(
+ UserImageAttribute.WORKSPACE_USER_IMAGE_FOLDER);
}
- private String removeWhiteSpaces(String filename){
- return filename.replaceAll("\\s+", "_");
- }
-
+
/**
* Update user image and save it as UserImageProperty
+ *
* @param path
*/
- private void updateUserImage(String path)
+ private void updateUserImage(String path)
{
- if (userImageAttr == null)
+ if (userImageAttr == null)
{
userImageAttr = new UserImageAttribute();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|