Author: dmaliarevich
Date: 2011-02-16 06:57:13 -0500 (Wed, 16 Feb 2011)
New Revision: 29173
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAction.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeContributionItem.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-6267 , base functionality was created.
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2011-02-16 10:33:04 UTC
(rev 29172)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2011-02-16 11:57:13 UTC
(rev 29173)
@@ -61,7 +61,8 @@
org.eclipse.ltk.ui.refactoring,
org.eclipse.core.expressions;bundle-version="3.4.100",
org.jboss.tools.common.text.ext;bundle-version="3.1.0",
- org.eclipse.jst.jsp.ui;visibility:=reexport
+ org.eclipse.jst.jsp.ui;visibility:=reexport,
+ org.jboss.tools.jst.jsp;bundle-version="3.2.0"
Bundle-Version: 3.2.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2011-02-16 10:33:04 UTC (rev 29172)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2011-02-16 11:57:13 UTC (rev 29173)
@@ -773,6 +773,20 @@
</visibleWhen>
</command>
</menuContribution>
+ <menuContribution
+ locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor.source.EditorContext?after=org.jboss.tools.jst.jsp.i18n.ExternalizeStringsContributionItem">
+ <dynamic
+
class="org.jboss.tools.jsf.web.validation.jsf2.action.CreateJSF2CompositeContributionItem"
+
id="org.jboss.tools.jsf.web.validation.jsf2.action.JSF2CreateCompositeContributionItem">
+ </dynamic>
+ </menuContribution>
+ <menuContribution
+
locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor.source.EditorContext?after=org.jboss.tools.jst.jsp.i18n.ExternalizeStringsContributionItem">
+ <dynamic
+
class="org.jboss.tools.jsf.web.validation.jsf2.action.CreateJSF2CompositeContributionItem"
+
id="org.jboss.tools.jsf.web.validation.jsf2.action.JSF2CreateCompositeContributionItem">
+ </dynamic>
+ </menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java 2011-02-16
10:33:04 UTC (rev 29172)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/JSFUIMessages.java 2011-02-16
11:57:13 UTC (rev 29173)
@@ -150,8 +150,8 @@
public static String Refactoring_JSF_2_Rename_Attr_Ref_Decl;
public static String NonExternalizedStringLiteral;
public static String NonExternalizedStringMarkerLabel;
+ public static String CreateJSF2Composite;
-
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, JSFUIMessages.class);
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties 2011-02-16
10:33:04 UTC (rev 29172)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/messages/messages.properties 2011-02-16
11:57:13 UTC (rev 29173)
@@ -127,3 +127,4 @@
Refactoring_JSF_2_Rename_Attr_Ref_Decl=Rename composite attribute reference in
declaration
NonExternalizedStringLiteral=Non externalized String literal; It should be moved to
resource bundles.
NonExternalizedStringMarkerLabel=Move String "{0}" to resource bundle.
+CreateJSF2Composite=Create JSF2 composite...
\ No newline at end of file
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAction.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAction.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeAction.java 2011-02-16
11:57:13 UTC (rev 29173)
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.web.validation.jsf2.action;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.jboss.tools.common.model.XModelObjectConstants;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil;
+import org.jboss.tools.jst.jsp.editor.IVisualContext;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
+import org.jboss.tools.jst.jsp.jspeditor.SourceEditorPageContext;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPPaletteInsertHelper;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.PaletteTaglibInserter;
+import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.jst.web.tld.URIConstants;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+public class CreateJSF2CompositeAction extends Action {
+
+ private final String IMPLEMENTATION = "composite:implementation";
//$NON-NLS-1$
+
+ private JSPMultiPageEditor editor;
+
+ public CreateJSF2CompositeAction() {
+ super();
+ }
+
+ @Override
+ public void run() {
+ editor = (JSPMultiPageEditor) PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ /*
+ * Get the selected text
+ */
+ ISelection selection = editor.getSelectionProvider().getSelection();
+ if (selection instanceof TextSelection) {
+ TextSelection textSelection = (TextSelection) selection;
+ String text = textSelection.getText();
+ /*
+ * Get composite template creator
+ */
+ InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(),
+ "Creating composite component", //$NON-NLS-1$
+ "Enter component's namespace and name:", "namespace:name",
//$NON-NLS-1$ //$NON-NLS-2$
+ null);
+ if (dlg.open() == Window.OK) {
+ /*
+ * Create all required files
+ */
+ String componentName = dlg.getValue();
+ String path = ""; //$NON-NLS-1$
+ String name = ""; //$NON-NLS-1$
+ String namespace = ""; //$NON-NLS-1$
+ int index = componentName.indexOf(":"); //$NON-NLS-1$
+ if (index != -1) {
+ namespace = componentName.substring(0, index);
+ name = componentName.substring(index+1, componentName.length());
+ }
+ path = componentName.replaceAll(":", "/"); //$NON-NLS-1$
//$NON-NLS-2$
+ if (!path.endsWith(".xhtml")) { //$NON-NLS-1$
+ path = path + ".xhtml"; //$NON-NLS-1$
+ }
+ IProject project = editor.getProject();
+ if (project != null) {
+ try {
+ IFile createdFile = JSF2ResourceUtil
+ .createCompositeComponentFile(project, new Path(path));
+ /*
+ * Add selected text to the template
+ */
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if (manager != null) {
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForEdit(createdFile);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ IDOMDocument document = domModel.getDocument();
+ NodeList list = document.getElementsByTagName(IMPLEMENTATION);
+ if (list.getLength() == 1) {
+ String content = document.getStructuredDocument().getText();
+ index = content.indexOf("<"+IMPLEMENTATION+">") +
("<"+IMPLEMENTATION+">").length(); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
+ content = content.subSequence(0, index) + "\n" + text +
content.subSequence(index, content.length()); //$NON-NLS-1$
+ domModel.reload(new ByteArrayInputStream(content.getBytes()));
+ model.save();
+ /*
+ * Register JSF 2 composite on the current page
+ */
+ IDocument doc =
editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ int offset = textSelection.getOffset();
+ int length = textSelection.getLength();
+ String replacement = "<" + componentName + "> </"
+ componentName + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ doc.replace(offset, length, replacement);
+ /*
+ * Register the required taglib
+ */
+ StructuredTextEditor ed = ((JSPMultiPageEditor) editor).getSourceEditor();
+ if (ed instanceof JSPTextEditor) {
+ String libraryUri = JSF2ResourceUtil.JSF2_URI_PREFIX + "/" +
namespace; //$NON-NLS-1$
+ PaletteTaglibInserter PaletteTaglibInserter = new PaletteTaglibInserter();
+ Properties p = new Properties();
+ p.put("selectionProvider", editor.getSelectionProvider());
//$NON-NLS-1$
+ p.setProperty(URIConstants.LIBRARY_URI, libraryUri);
+ p.setProperty(URIConstants.LIBRARY_VERSION, ""); //$NON-NLS-1$
+ p.setProperty(URIConstants.DEFAULT_PREFIX, namespace);
+ p.setProperty(JSPPaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, "true");
//$NON-NLS-1$
+ p.setProperty(XModelObjectConstants.REFORMAT, "yes"); //$NON-NLS-1$
+ p.setProperty(XModelObjectConstants.START_TEXT,
+ "<%@ taglib uri=\""+libraryUri+"\"
prefix=\"" +namespace+ "\" %>\\n"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ PaletteTaglibInserter.inserTaglib(ed.getTextViewer().getDocument(), p);
+ }
+ /*
+ * Add required taglibs to the composite file
+ */
+ IVisualContext context = editor.getJspEditor().getPageContext();
+ List<TaglibData> taglibs = null;
+ if (context instanceof SourceEditorPageContext) {
+ SourceEditorPageContext sourcePageContext = (SourceEditorPageContext)
context;
+ taglibs = sourcePageContext.getTagLibs();
+ }
+ }
+ }
+ } catch (CoreException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } catch (IOException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } catch (BadLocationException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } finally {
+ if (model != null) {
+ model.releaseFromEdit();
+ }
+ }
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeContributionItem.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeContributionItem.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/action/CreateJSF2CompositeContributionItem.java 2011-02-16
11:57:13 UTC (rev 29173)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.web.validation.jsf2.action;
+
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.swt.widgets.Menu;
+import org.jboss.tools.jsf.messages.JSFUIMessages;
+
+public class CreateJSF2CompositeContributionItem extends ActionContributionItem {
+
+ public CreateJSF2CompositeContributionItem() {
+ super(new CreateJSF2CompositeAction());
+ }
+
+ @Override
+ public void fill(Menu parent, int index) {
+ getAction().setText(JSFUIMessages.CreateJSF2Composite);
+ super.fill(parent, index);
+ }
+}