From a2085546a6fbf66da66d7a8ea2bf0db8b0b94f25 Mon Sep 17 00:00:00 2001 From: "gyeongmin.ju" Date: Thu, 27 Mar 2014 17:13:41 +0900 Subject: [PATCH] UIB : Fix null point exception on ThumbnailManager, HtmlMetaFileData, SnippetManager Signed-off-by: gyeongmin.ju Change-Id: I43810bf0c8b3112f58100038f1cb8111b9415cc2 --- .../webuibuilder/model/app/ThumbnailManager.java | 26 -- .../model/filedata/HtmlMetaFileData.java | 10 +- .../snippet/manager/SnippetManager.java | 405 +++++++++++---------- 3 files changed, 209 insertions(+), 232 deletions(-) diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/ThumbnailManager.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/ThumbnailManager.java index cd5022d..48c2a32 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/ThumbnailManager.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/ThumbnailManager.java @@ -25,11 +25,9 @@ package org.tizen.webuibuilder.model.app; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.eclipse.swt.widgets.Display; import org.tizen.webuibuilder.bridge.DesignerGoingBridge; -import org.tizen.webuibuilder.bridge.DesignerGoingBridge.WidgetPosition; import org.tizen.webuibuilder.browserwidget.ImageBufferedBrowser; import org.tizen.webuibuilder.browserwidget.ImageBufferedBrowserWidget.ContentsAreaChangedListener; @@ -38,7 +36,6 @@ public class ThumbnailManager implements Runnable { private List imageBufferedBrowserList; private DesignerGoingBridge goingBridge; - private Map allWidgetPositions; private Display display; private ContentsAreaChangedListener listener; private int tickTime = 40; @@ -49,8 +46,6 @@ public class ThumbnailManager implements Runnable { this.display = display; this.listener = listener; - allWidgetPositions = null; - display.timerExec(tickTime, this); } @@ -74,29 +69,8 @@ public class ThumbnailManager implements Runnable { return imageBufferedBrowserList.get(index); } - public Map getWidgetPositions() { - if (allWidgetPositions == null) { - allWidgetPositions = goingBridge.getAllWidgetPositions(); - } - return allWidgetPositions; - } - - public WidgetPosition getWidgetPosition(String partId) { - Map pos = getWidgetPositions(); - return (pos != null) ? pos.get(partId) : null; - } - - private void invalidateWidgetPositions() { - allWidgetPositions = null; - } - public void setBrowserSize(int index, int width, int height) { getBrowser(index).setBrowserSize(width, height); - invalidateWidgetPositions(); - } - - public void updateSizeEditings() { - invalidateWidgetPositions(); } @Override diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/filedata/HtmlMetaFileData.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/filedata/HtmlMetaFileData.java index 9e296fc..d4320bb 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/filedata/HtmlMetaFileData.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/filedata/HtmlMetaFileData.java @@ -34,19 +34,13 @@ import org.w3c.dom.Document; public class HtmlMetaFileData { - public class Page { + private class Page { public String name; public Part rootPart; - // public List nscreenModelList = new - // ArrayList(); - - public Page(String name, Part rootPart/* - * , List nscreenModelList - */) { + public Page(String name, Part rootPart) { this.name = name; this.rootPart = rootPart; - // this.nscreenModelList = nscreenModelList; } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/manager/SnippetManager.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/manager/SnippetManager.java index c7a80d0..2189626 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/manager/SnippetManager.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/manager/SnippetManager.java @@ -20,7 +20,6 @@ * */ - package org.tizen.webuibuilder.snippet.manager; import java.io.File; @@ -38,203 +37,213 @@ import org.tizen.webuibuilder.snippet.loader.SnippetLoader; import org.tizen.webuibuilder.snippet.model.ISnippet; import org.tizen.webuibuilder.utility.ResourceUtil; - public class SnippetManager implements ISnippetManager { - private Map snippets = null; - private Logger logger = LoggerFactory.getLogger(getClass()); - - public SnippetManager() { - super(); - snippets = new HashMap(); - load(); - } - - /* - * (non-Javadoc) - * - * @see org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#getSnippets() - */ - @Override - public Collection getSnippets() { - return snippets.values(); - } - - /* - * (non-Javadoc) - * - * @see - * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#create(org.tizen.webuibuilder - * .feature.snippet.model.ISnippet) - */ - @Override - public boolean create(ISnippet snippet) { - // Create ID - String id = createId(); - snippet.setId(id); - - // Save - String path = getSnippetPath(snippet); - SnippetLoader snippetLoader = new SnippetLoader(); - snippetLoader.snippet = snippet; - if (!snippetLoader.save(path)) { - return false; - } - Integer key = getKey(snippet); - snippets.put(key, snippet); - return true; - } - - /* - * (non-Javadoc) - * - * @see - * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#remove(org.tizen.webuibuilder - * .feature.snippet.model.ISnippet) - */ - @Override - public boolean remove(ISnippet snippet) { - String path = getSnippetPath(snippet); - File file = new File(path); - if (!FileUtil.recursiveDelete(file)) { - return false; - } - Integer key = getKey(snippet); - snippets.remove(key); - return true; - } - - /* - * (non-Javadoc) - * - * @see - * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#rename(org.tizen.webuibuilder - * .feature.snippet.model.ISnippet, java.lang.String) - */ - @Override - public boolean rename(ISnippet snippet, String name) { - // exist in collection ? - Integer key = getKey(snippet); - ISnippet selectedSnippet = snippets.get(key); - if (selectedSnippet == null) { - return false; - } - // Remove old snippet - if (!remove(selectedSnippet)) { - return false; - } - // Rename - snippet.setName(name); - // Create new snippet - if (!create(snippet)) { - return false; - } - return true; - } - - public boolean importSnippet(String path) { - SnippetLoader snippetLoader = new SnippetLoader(); - ISnippet snippet = snippetLoader.load(path); - if (snippet == null) { // Load snippet fail - return false; - } - if (!create(snippet)) { // Create snippet fail - return false; - } - return true; - } - - /* - * (non-Javadoc) - * - * @see org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#importSnippet(org.tizen. - * webuibuilder.feature.snippet.model.ISnippet) - */ - @Override - public boolean importSnippet(ISnippet snippet) { - return create(snippet); - } - - /* - * (non-Javadoc) - * - * @see org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#exportSnippet(org.tizen. - * webuibuilder.feature.snippet.model.ISnippet) - */ - @Override - public boolean exportSnippet(ISnippet snippet, String path) { - // Remove ID - snippet.setId(""); - SnippetLoader snippetLoader = new SnippetLoader(); - snippetLoader.snippet = snippet; - if (!snippetLoader.save(path + File.separator + snippet.getName())) { - return false; - } - return true; - } - - private String getDefaultPath() { - String path = ResourceUtil.getAbsolutePath(InternalMessages.SNIPPET_FOLDER_PATH); - return path; - } - - private String getSnippetPath(ISnippet snippet) { - String path = getDefaultPath() + File.separator + snippet.getId() + "." + snippet.getName(); - return path; - } - - private void load() { - snippets = load(getDefaultPath()); - } - - private Map load(String path) { - File folder = new File(path); - if (!folder.exists()) { - return null; - } - if (!folder.isDirectory()) { - return null; - } - - Map snippets = new HashMap(); - File[] files = folder.listFiles(); - for (File file : files) { - // snippet directory has file - if (!file.isDirectory()) { - logger.warn("snippet directory has file"); - continue; - } - - String snippetPath = path + IPath.SEPARATOR + file.getName(); - ISnippetLoader loader = new SnippetLoader(); - // snippet load fail - ISnippet snippet = loader.load(snippetPath); - if (snippet == null) { - logger.warn("snippet load fail"); - continue; - } - - // snippet id consistency broken - Integer key = getKey(snippet); - if (snippets.containsKey(key)) { - logger.warn("snippet id consistency broken"); - return null; - } - snippets.put(key, snippet); - } - return snippets; - } - - protected Integer getKey(ISnippet snippet) { - return Integer.parseInt(snippet.getId()); - } - - protected String createId() { - // initialize id - Integer id = Integer.valueOf(1); - while (snippets.containsKey(id)) { - id = id + 1; - } - return id.toString(); - } + private Map snippets = null; + private Logger logger = LoggerFactory.getLogger(getClass()); + + public SnippetManager() { + super(); + snippets = new HashMap(); + load(); + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#getSnippets + * () + */ + @Override + public Collection getSnippets() { + if (snippets == null) { + return null; + } + + return snippets.values(); + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#create + * (org.tizen.webuibuilder .feature.snippet.model.ISnippet) + */ + @Override + public boolean create(ISnippet snippet) { + // Create ID + String id = createId(); + snippet.setId(id); + + // Save + String path = getSnippetPath(snippet); + SnippetLoader snippetLoader = new SnippetLoader(); + snippetLoader.snippet = snippet; + if (!snippetLoader.save(path)) { + return false; + } + Integer key = getKey(snippet); + snippets.put(key, snippet); + return true; + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#remove + * (org.tizen.webuibuilder .feature.snippet.model.ISnippet) + */ + @Override + public boolean remove(ISnippet snippet) { + String path = getSnippetPath(snippet); + File file = new File(path); + if (!FileUtil.recursiveDelete(file)) { + return false; + } + Integer key = getKey(snippet); + snippets.remove(key); + return true; + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#rename + * (org.tizen.webuibuilder .feature.snippet.model.ISnippet, + * java.lang.String) + */ + @Override + public boolean rename(ISnippet snippet, String name) { + // exist in collection ? + Integer key = getKey(snippet); + ISnippet selectedSnippet = snippets.get(key); + if (selectedSnippet == null) { + return false; + } + // Remove old snippet + if (!remove(selectedSnippet)) { + return false; + } + // Rename + snippet.setName(name); + // Create new snippet + if (!create(snippet)) { + return false; + } + return true; + } + + public boolean importSnippet(String path) { + SnippetLoader snippetLoader = new SnippetLoader(); + ISnippet snippet = snippetLoader.load(path); + if (snippet == null) { // Load snippet fail + return false; + } + if (!create(snippet)) { // Create snippet fail + return false; + } + return true; + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#importSnippet + * (org.tizen. webuibuilder.feature.snippet.model.ISnippet) + */ + @Override + public boolean importSnippet(ISnippet snippet) { + return create(snippet); + } + + /* + * (non-Javadoc) + * + * @see + * org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#exportSnippet + * (org.tizen. webuibuilder.feature.snippet.model.ISnippet) + */ + @Override + public boolean exportSnippet(ISnippet snippet, String path) { + // Remove ID + snippet.setId(""); + SnippetLoader snippetLoader = new SnippetLoader(); + snippetLoader.snippet = snippet; + if (!snippetLoader.save(path + File.separator + snippet.getName())) { + return false; + } + return true; + } + + private String getDefaultPath() { + String path = ResourceUtil + .getAbsolutePath(InternalMessages.SNIPPET_FOLDER_PATH); + return path; + } + + private String getSnippetPath(ISnippet snippet) { + String path = getDefaultPath() + File.separator + snippet.getId() + "." + + snippet.getName(); + return path; + } + + private void load() { + snippets = load(getDefaultPath()); + } + + private Map load(String path) { + File folder = new File(path); + if (!folder.exists()) { + return null; + } + if (!folder.isDirectory()) { + return null; + } + + Map snippets = new HashMap(); + File[] files = folder.listFiles(); + for (File file : files) { + // snippet directory has file + if (!file.isDirectory()) { + logger.warn("snippet directory has file"); + continue; + } + + String snippetPath = path + IPath.SEPARATOR + file.getName(); + ISnippetLoader loader = new SnippetLoader(); + // snippet load fail + ISnippet snippet = loader.load(snippetPath); + if (snippet == null) { + logger.warn("snippet load fail"); + continue; + } + + // snippet id consistency broken + Integer key = getKey(snippet); + if (snippets.containsKey(key)) { + logger.warn("snippet id consistency broken"); + return null; + } + snippets.put(key, snippet); + } + return snippets; + } + + protected Integer getKey(ISnippet snippet) { + return Integer.parseInt(snippet.getId()); + } + + protected String createId() { + // initialize id + Integer id = Integer.valueOf(1); + while (snippets.containsKey(id)) { + id = id + 1; + } + return id.toString(); + } } -- 2.7.4