--- /dev/null
+/*
+ * UI Builder
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+package org.tizen.webuibuilder.gef.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.gef.commands.Command;
+import org.tizen.webuibuilder.BuilderConstants;
+import org.tizen.webuibuilder.model.app.AppManagerForHTML;
+import org.tizen.webuibuilder.model.filedata.PageFileData;
+import org.tizen.webuibuilder.model.page.PageData;
+import org.tizen.webuibuilder.model.page.PageDataForHTML;
+import org.tizen.webuibuilder.utility.DomUtil;
+import org.w3c.dom.Node;
+
+public class CreatePageCommand extends Command {
+
+ private AppManagerForHTML appManager;
+ private List<PageData> pageDatas;
+ private Node pageNode;
+
+ private final String BODY_ELEMENT = "//BODY";
+ private final String BODY_ELEMENT_LOWER = "//body";
+
+ public CreatePageCommand(AppManagerForHTML appManager, String html, String name) {
+ this.appManager = appManager;
+
+ init(html, name);
+ }
+
+ public void init(String html, String name) {
+ PageFileData pageFileData = appManager.loadPageFileData(html, name);
+
+ if(pageFileData == null || pageFileData.getRootPartList() == null) {
+ return;
+ }
+
+ int size = pageFileData.getRootPartList().size();
+ pageDatas = new ArrayList<PageData>(size);
+
+ for(int i = 0; i < size; i++) {
+ PageData pageData = new PageDataForHTML(BuilderConstants.EMPTY,
+ pageFileData, i, pageFileData.getDocument(),
+ appManager.getDescriptorManager(), null);
+
+ if(pageData != null) {
+ pageDatas.add(pageData);
+ }
+ }
+
+ Node bodyNode = DomUtil.getBodyNode(pageFileData.getDocument(), BODY_ELEMENT);
+ pageNode = DomUtil.importedNode(appManager.getDocument(), bodyNode.getFirstChild());
+ }
+
+ @Override
+ public boolean canExecute() {
+ return (pageDatas != null && pageNode != null) ? true : false;
+ }
+
+ @Override
+ public void execute() {
+ if(!canExecute()) {
+ return;
+ }
+
+ DomUtil.appendPageNode(appManager.getDocument(), BODY_ELEMENT_LOWER, pageNode);
+
+ for(PageData pagaData : pageDatas) {
+ appManager.addPage(pagaData, true);
+ }
+
+ }
+
+ @Override
+ public void undo() {
+ DomUtil.removePageNode(this.appManager.getDocument(), BODY_ELEMENT_LOWER, pageNode);
+
+ for(PageData pagaData : pageDatas) {
+ appManager.removePage(pagaData);
+ }
+
+ }
+
+}
while (child.canSetPropertyValue(PROPERTY_ID, id + String.valueOf(idIndex)) != WidgetValidator.OK) {
idIndex++;
}
- child.setPropertyValue(PROPERTY_ID, id + String.valueOf(idIndex));
+
+ String newId = id + String.valueOf(idIndex);
+
+ if(child.getElement() != null) {
+ child.getElement().setAttribute(PROPERTY_ID, newId);
+ }
+
+ child.setPropertyValue(PROPERTY_ID, newId);
} else {
child.setPropertyValue(PROPERTY_ID, propertyId);
}
package org.tizen.webuibuilder.model.app;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.StringBufferInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import org.w3c.dom.NodeList;
-@SuppressWarnings("deprecation")
public class AppManagerForHTML extends AppManager {
private Document document;
return load(BuilderConstants.INDEX_HTML_FILE);
}
+ public PageFileData loadPageFileData(String html, String pageName) {
+ if (html == null || pageName == null) {
+ return null;
+ }
+
+ String page = "data-role=\"page\""; //$NON-NLS-1$
+ String newHtml = null;
+ if (html.contains(page)) {
+ String id = BuilderConstants.PROPERTY_ID + BuilderConstants.EQUAL
+ + BuilderConstants.QUOTATION_MARK;
+ int startIndex = html.indexOf(id, html.indexOf(page)) + 4;
+ String startHtml = html.substring(0, startIndex);
+ int endIndex = html.indexOf(BuilderConstants.QUOTATION_MARK,
+ startIndex);
+ String endHtml = html.substring(endIndex, html.length());
+ newHtml = startHtml + pageName + endHtml;
+ }
+ return (newHtml != null) ? HtmlReader.loadHtmlStream(this,
+ new ByteArrayInputStream(newHtml.getBytes())) : null;
+ }
+
public void addPage(String html, String pageName) {
if (html == null || pageName == null) {
return;
return;
}
- StringBufferInputStream stream = new StringBufferInputStream(html);
+ ByteArrayInputStream stream = new ByteArrayInputStream(html.getBytes());
PageFileData pageFileData = HtmlReader.loadHtmlStream(this, stream);
if (pageFileData == null) {
return;
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
+import org.tizen.webuibuilder.gef.commands.CreatePageCommand;
import org.tizen.webuibuilder.model.app.AppManager;
+import org.tizen.webuibuilder.model.app.AppManagerForHTML;
import org.tizen.webuibuilder.pagetemplate.ui.wizards.NewPageWizard;
import org.tizen.webuibuilder.ui.actions.WebUIBuilderActionConstants;
import org.tizen.webuibuilder.ui.contextmenu.Messages;
IStructuredSelection selection = new StructuredSelection(appManager);
newpage.init(workbench, selection);
WizardDialog dialog = new WizardDialog(shell, newpage);
- dialog.open();
+ int r = dialog.open();
+
+ if(r == Window.OK) {
+ if(!(appManager instanceof AppManagerForHTML)) {
+ return;
+ }
+ AppManagerForHTML manager = (AppManagerForHTML) appManager;
+
+ getCommandStack().execute(new CreatePageCommand(manager, newpage.getTemplate().getDescriptor().getText(), newpage.getName()));
+
+ }
}
}
*/
@Override
public boolean run() {
- if (!(model instanceof AppManagerForHTML)) {
- return false;
- }
- AppManagerForHTML manager = (AppManagerForHTML) model;
- manager.addPage(template.getDescriptor().getText(), name);
+// if (!(model instanceof AppManagerForHTML)) {
+// return false;
+// }
+// AppManagerForHTML manager = (AppManagerForHTML) model;
+// manager.addPage(template.getDescriptor().getText(), name);
// PageFileData pageFileData = PageReader.readPage(template.getDescriptor().getText(), manager.getPartFactory());
// PageData pageData = new PageDataForHTML(BuilderConstants.EMPTY, pageFileData, 0,
// pageFileData.getDocument(), manager.getDescriptorManager(),
// manager.addPage(pageData, true);
// manager.addPage(pageFileData);
// manager.addPage(template.getDescriptor().getText(), name);
- return true;
+
+ return (template != null &&
+ template.getDescriptor() != null &&
+ template.getDescriptor().getText() != null &&
+ !template.getDescriptor().getText().isEmpty());
}
}
\ No newline at end of file
private ISelection fSelection = null;
// private NewPageWizardFirstPage fFirstPage = null;
private NewPageWizardSecondPage fSecondPage = null;
+
+ private String name = null;
+ private ITemplate template = null;
/*
* (non-Javadoc)
@Override
public boolean performFinish() {
// get inputs
- String name = fSecondPage.getPageName();
- ITemplate template = fSecondPage.getTemplate();
+ this.name = fSecondPage.getPageName();
+ this.template = fSecondPage.getTemplate();
// create policies
NewPagePolicy newPagePolicy = new NewPagePolicy(appManager, name, template);
processor.add(newPagePolicy);
return processor.run();
}
+
+ public String getName() {
+ return name;
+ }
+
+ public ITemplate getTemplate() {
+ return template;
+ }
+
+
}
--- /dev/null
+/*
+ * UI Builder
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.webuibuilder.utility;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.tizen.webuibuilder.BuilderConstants;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+public class DomUtil {
+
+
+ /**
+ * @param doc
+ * @param xpath "//BODY" or "//body"
+ * @return
+ */
+ public static Node getBodyNode(Document doc, String xpath) {
+ XPathFactory xpathFactory = XPathFactory.newInstance();
+ XPath expr = xpathFactory.newXPath();
+ Object bodyNodeset = null;
+ try {
+ if (xpath != null && !xpath.equals(BuilderConstants.EMPTY)) {
+ bodyNodeset = expr.evaluate(xpath, doc, XPathConstants.NODE);
+ }
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+
+ if (bodyNodeset instanceof Node) {
+ return (Node) bodyNodeset;
+ }
+
+ return null;
+ }
+
+ public static Node importedNode(Document targetDocument, Node pageNode) {
+ return targetDocument.importNode(pageNode, true);
+ }
+
+ /**
+ * @param targetDocument
+ * @param pageNode imported pageNode
+ */
+ public static void appendPageNode(Document targetDocument, String xpath, Node pageNode) {
+ Node targetBodyNode = getBodyNode(targetDocument, xpath);
+
+ if(targetBodyNode == null) {
+ return;
+ }
+
+ targetBodyNode.appendChild(pageNode);
+ }
+
+ public static void removePageNode(Document targetDocument, String xpath, Node pageNode) {
+ Node targetBodyNode = getBodyNode(targetDocument, xpath);
+
+ if(targetBodyNode == null) {
+ return;
+ }
+
+ targetBodyNode.removeChild(pageNode);
+ }
+
+
+}