From 6106c129c7406458acbe589f5bb54d93112d358c Mon Sep 17 00:00:00 2001 From: jeonghwan kim Date: Thu, 8 May 2014 15:43:23 +0900 Subject: [PATCH] ResourcesView : 1. Modify selection condition 2. Modify import file (using Job (thread) for progress monitor) Change-Id: I16530e424fdd1595e16cd9e53fd3da361d82d0d8 Signed-off-by: jeonghwan kim --- .../ui/views/resources/ResourcesPage.java | 136 +++++++++++++++++---- 1 file changed, 114 insertions(+), 22 deletions(-) diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/resources/ResourcesPage.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/resources/ResourcesPage.java index 4c99956..e8cd0fe 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/resources/ResourcesPage.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/resources/ResourcesPage.java @@ -24,6 +24,7 @@ package org.tizen.webuibuilder.ui.views.resources; import java.io.File; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; @@ -37,8 +38,11 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.gef.dnd.TemplateTransferDragSourceListener; +import org.eclipse.gef.internal.ui.palette.editparts.SliderPaletteEditPart; import org.eclipse.gef.palette.CombinedTemplateCreationEntry; import org.eclipse.gef.palette.PaletteDrawer; import org.eclipse.gef.palette.PaletteRoot; @@ -76,6 +80,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; @@ -84,6 +89,8 @@ import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.part.Page; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.tizen.common.util.Assert; import org.tizen.common.util.EFSUtil; import org.tizen.webuibuilder.gef.dnd.model.ResourceTemplate; @@ -92,8 +99,10 @@ import org.tizen.webuibuilder.ui.editor.PageDesigner; import org.tizen.webuibuilder.ui.views.resources.model.Resource; import org.tizen.webuibuilder.ui.views.resources.viewer.ResourcesEntryEditPart; import org.tizen.webuibuilder.ui.views.resources.viewer.ResourcesViewer; +import org.tizen.webuibuilder.utility.Platform; +@SuppressWarnings("restriction") public class ResourcesPage extends Page implements PalettePage, ModifyListener, ISelectionChangedListener, ISelectionProvider, MouseListener { @@ -113,6 +122,7 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, protected Composite viewerComposite = null; protected Text filterText = null; protected Combo filterCombo = null; + protected Label statusBar = null; protected IFolder currentFolder = null; protected List resources = null; @@ -133,6 +143,8 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, private SelectionProvider selectionProvider = new SelectionProvider(); private boolean isDoubleClicked = false; + private static Logger logger = LoggerFactory.getLogger(ResourcesPage.class); + public ResourcesPage(ResourcesView view) { super(); this.view = view; @@ -194,6 +206,9 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, viewer.setContextMenu(new ResourcesViewContextMenu(viewer, getActionRegistry())); viewer.setKeyHandler(new ResourcesViewKeyHandler(this, viewer)); + statusBar = new Label(rootComposite, SWT.NONE); + statusBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + // For DnD dragSourceListener = new TemplateTransferDragSourceListener(viewer); dropTargetListener = new ResourcesViewDropTargetAdapter(this); @@ -355,12 +370,12 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, return folder; } - public void setInput() { + protected void setInput() { IFolder folder = getDefaultFolder(); setInput(folder); } - private void setInput(IFolder folder) { + protected void setInput(IFolder folder) { Assert.notNull(folder); currentFolder = folder; resources = getResources(currentFolder); @@ -370,7 +385,6 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, private void setInput(List resources) { PaletteRoot root = getPaletteRoot(currentFolder, resources); viewer.setPaletteRoot(root); - viewer.deselectAll(); refreshViewer(); } @@ -473,7 +487,17 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, Object object = ss.getFirstElement(); if (object instanceof ResourcesEntryEditPart) { setSelection(selection); - } else { + ResourcesEntryEditPart editPart = (ResourcesEntryEditPart) object; + Object model = editPart.getModel(); + Assert.isTrue(model instanceof CombinedTemplateCreationEntry); + CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) model; + String label = entry.getLabel(); + String description = entry.getDescription(); + String text = label + " " + description; + statusBar.setText(text); + } else if (object instanceof SliderPaletteEditPart) { + logger.info(object.getClass().toString()); + logger.info(object.toString()); setSelection(StructuredSelection.EMPTY); } updateActions(); @@ -545,10 +569,6 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, } File file = new File(selected); - if (!file.exists()) { - return; - } - importFile(file); } @@ -562,23 +582,58 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, } File file = new File(selected); + importFile(file); + } + + private boolean hasFile(File file) { + for (Resource resource : resources) { + IResource iResource = resource.getResource(); + String resourcePath = iResource.getLocation().toString(); + String filePath = Platform.getCorrectedPath(file.getPath()); + if (resourcePath.equals(filePath)) { + return true; + } + } + return false; + } + + public void importFile(final File file) { + Assert.notNull(file); if (!file.exists()) { return; } - importFile(file); - } - - public void importFile(File file) { - IFile dstFile = currentFolder.getFile(file.getName()); - try { - IProgressMonitor monitor = new NullProgressMonitor(); - EFSUtil.copy(file.toURI(), dstFile.getLocationURI(), EFS.OVERWRITE, monitor); - dstFile.refreshLocal(IResource.DEPTH_INFINITE, monitor); - } catch (CoreException e) { + if (hasFile(file)) { return; } - refresh(); + + final IFile dstFile = currentFolder.getFile(file.getName()); + Job job = new Job("Import Files") { + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + logger.info(monitor.getClass().toString()); + try { + EFSUtil.copy(file.toURI(), dstFile.getLocationURI(), EFS.OVERWRITE, monitor); + } catch (CoreException e) { + e.printStackTrace(); + return Status.CANCEL_STATUS; + } + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + refresh(); + } + }); + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); } public void refresh() { @@ -661,6 +716,32 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, setInput(displayResources); } + private String getFileSize(File file) { + double size = file.length(); + int i = 0; + while (size > 1024) { + size = size / 1024; + i++; + } + String surfix = ""; + DecimalFormat format = null; + if (i == 0) { + format = new DecimalFormat("####"); + surfix = "B"; + } else if (i == 1) { + format = new DecimalFormat("####"); + surfix = "KB"; + } else if (i == 2) { + format = new DecimalFormat("####.00"); + surfix = "MB"; + } else if (i == 3) { + format = new DecimalFormat("####.00"); + surfix = "GB"; + } + + return format.format(size) + surfix; + } + protected void refreshViewer() { // PaletteRoot PaletteRoot root = viewer.getPaletteRoot(); @@ -679,10 +760,17 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, Assert.isTrue(template instanceof ResourceTemplate); ResourceTemplate resourceTemplate = (ResourceTemplate) template; Resource resource = resourceTemplate.getResource(); + final IResource iResource = resource.getResource(); + File file = new File(iResource.getLocation().toString()); + if (!file.isFile()) { + continue; + } + final String fileSize = getFileSize(file); + templateEntry.setDescription(fileSize); if (resource.getType() != Resource.IMAGE) { continue; } - final IResource iResource = resource.getResource(); + Display.getCurrent().asyncExec(new Runnable() { /* * (non-Javadoc) @@ -693,11 +781,14 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, public void run() { ImageLoader imageLoader = new ImageLoader(); ImageData[] imageData = imageLoader.load(iResource.getLocation().toString()); + String description = + imageData[0].width + " x " + imageData[0].height + " " + fileSize; ImageData resizedImageData = imageData[0].scaledTo(ITEM_WIDTH, ITEM_HEIGHT); ImageDescriptor imageDescriptor = ImageDescriptor.createFromImageData(resizedImageData); templateEntry.setSmallIcon(imageDescriptor); templateEntry.setLargeIcon(imageDescriptor); + templateEntry.setDescription(description); } }); } @@ -714,6 +805,7 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, IFile file = (IFile) resource; imageDescriptor = getImageDescriptor(file); } else { + logger.warn("undefined condition"); } return imageDescriptor; } @@ -780,7 +872,7 @@ public class ResourcesPage extends Page implements PalettePage, ModifyListener, } private void checkDoubleClick() { - ISelection selection = getSelection(); + ISelection selection = viewer.getSelection(); Assert.isTrue(selection instanceof IStructuredSelection); IStructuredSelection ss = (IStructuredSelection) selection; Object object = ss.getFirstElement(); -- 2.7.4