]>
git.argeo.org Git - gpl/argeo-suite.git/blob - argeo/library/ui/DocumentsFileComposite.java
1 package org
.argeo
.library
.ui
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.Files
;
5 import java
.nio
.file
.Path
;
6 import java
.nio
.file
.spi
.FileSystemProvider
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.cms
.fs
.CmsFsUtils
;
13 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
14 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
15 import org
.argeo
.eclipse
.ui
.fs
.FsUiUtils
;
16 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.browser
.Browser
;
19 import org
.eclipse
.swt
.custom
.SashForm
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Label
;
26 * Default Documents file composite: a sashForm with a browser in the middle and
27 * meta data at right hand side.
29 public class DocumentsFileComposite
extends Composite
{
30 private static final long serialVersionUID
= -7567632342889241793L;
32 private final static Log log
= LogFactory
.getLog(DocumentsFileComposite
.class);
34 private final Node currentBaseContext
;
36 // UI Parts for the browser
37 private Composite rightPannelCmp
;
39 public DocumentsFileComposite(Composite parent
, int style
, Node context
, FileSystemProvider fsp
) {
41 this.currentBaseContext
= context
;
42 this.setLayout(EclipseUiUtils
.noSpaceGridLayout());
43 SashForm form
= new SashForm(this, SWT
.HORIZONTAL
);
45 Composite centerCmp
= new Composite(form
, SWT
.BORDER
| SWT
.NO_FOCUS
);
46 createDisplay(centerCmp
);
48 rightPannelCmp
= new Composite(form
, SWT
.NO_FOCUS
);
50 Path path
= CmsFsUtils
.getPath(fsp
, context
);
51 setOverviewInput(path
);
52 form
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
53 form
.setWeights(new int[] { 55, 20 });
56 private void createDisplay(final Composite parent
) {
57 parent
.setLayout(EclipseUiUtils
.noSpaceGridLayout());
58 Browser browser
= new Browser(parent
, SWT
.NONE
);
59 // browser.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
61 browser
.setLayoutData(EclipseUiUtils
.fillAll());
62 // FIXME make it more robust
63 String url
= CmsUiUtils
.getDataUrl(currentBaseContext
, UiContext
.getHttpRequest());
64 // FIXME issue with the redirection to https
65 if (url
.startsWith("http://") && !url
.startsWith("http://localhost"))
66 url
= "https://" + url
.substring("http://".length(), url
.length());
67 if (log
.isTraceEnabled())
68 log
.debug("Trying to display " + url
);
70 browser
.layout(true, true);
74 * Recreates the content of the box that displays information about the current
77 private void setOverviewInput(Path path
) {
79 EclipseUiUtils
.clear(rightPannelCmp
);
80 rightPannelCmp
.setLayout(new GridLayout());
82 // if (isImg(context)) {
83 // EditableImage image = new Img(parent, RIGHT, context,
85 // image.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
90 Label contextL
= new Label(rightPannelCmp
, SWT
.NONE
);
91 contextL
.setText(path
.getFileName().toString());
92 contextL
.setFont(EclipseUiUtils
.getBoldFont(rightPannelCmp
));
93 addProperty(rightPannelCmp
, "Last modified", Files
.getLastModifiedTime(path
).toString());
94 // addProperty(rightPannelCmp, "Owner",
95 // Files.getOwner(path).getName());
96 if (Files
.isDirectory(path
)) {
97 addProperty(rightPannelCmp
, "Type", "Folder");
99 String mimeType
= Files
.probeContentType(path
);
100 if (EclipseUiUtils
.isEmpty(mimeType
))
101 mimeType
= "<i>Unknown</i>";
102 addProperty(rightPannelCmp
, "Type", mimeType
);
103 addProperty(rightPannelCmp
, "Size", FsUiUtils
.humanReadableByteCount(Files
.size(path
), false));
106 rightPannelCmp
.layout(true, true);
107 } catch (IOException e
) {
108 throw new IllegalStateException("Cannot display details for " + path
.toString(), e
);
112 // Simplify UI implementation
113 private void addProperty(Composite parent
, String propName
, String value
) {
114 Label propLbl
= new Label(parent
, SWT
.NONE
);
115 // propLbl.setText(ConnectUtils.replaceAmpersand(propName + ": " + value));
116 propLbl
.setText(value
);
117 // CmsUiUtils.markup(propLbl);