Repository: syncope Updated Branches: refs/heads/master 12d481a85 -> 6fee50d75
http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagInfo.java ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagInfo.java b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagInfo.java new file mode 100644 index 0000000..a406398 --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagInfo.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.syncope.ide.eclipse.plugin.editors.htmlhelpers; + +import java.util.ArrayList; +import java.util.List; + +public class TagInfo { + + private String tagName; + private boolean hasBody; + private boolean emptyTag; + private String description; + private List<AttributeInfo> attributes = new ArrayList<AttributeInfo>(); + private List<String> children = new ArrayList<String>(); + public static final int NONE = 0; + public static final int EVENT = 1; + public static final int FORM = 2; + + public TagInfo(final String tagName, final boolean hasBody) { + this(tagName, hasBody, false); + } + + public TagInfo(final String tagName, final boolean hasBody, final boolean emptyTag) { + this.tagName = tagName; + this.hasBody = hasBody; + this.emptyTag = emptyTag; + } + + public String getTagName() { + return this.tagName; + } + + public boolean hasBody() { + return this.hasBody; + } + + public boolean isEmptyTag() { + return this.emptyTag; + } + + public void addAttributeInfo(final AttributeInfo attribute) { + int i = 0; + for ( ; i < attributes.size(); i++) { + AttributeInfo info = attributes.get(i); + if (info.getAttributeName().compareTo(attribute.getAttributeName()) > 0) { + break; + } + } + this.attributes.add(i, attribute); + } + + public AttributeInfo[] getAttributeInfo() { + return this.attributes.toArray(new AttributeInfo[this.attributes.size()]); + } + + public AttributeInfo[] getRequiredAttributeInfo() { + ArrayList<AttributeInfo> list = new ArrayList<AttributeInfo>(); + for (int i = 0; i < attributes.size(); i++) { + AttributeInfo info = (AttributeInfo) attributes.get(i); + if (info.isRequired()) { + list.add(info); + } + } + return list.toArray(new AttributeInfo[list.size()]); + } + + public AttributeInfo getAttributeInfo(final String name) { + for (int i = 0 ; i < attributes.size() ; i++) { + AttributeInfo info = attributes.get(i); + if (info.getAttributeName().equals(name)) { + return info; + } + } + return null; + } + + public void addChildTagName(final String name) { + children.add(name); + } + + public String[] getChildTagNames() { + return children.toArray(new String[children.size()]); + } + + @Override public boolean equals(final Object obj) { + if (obj instanceof TagInfo) { + TagInfo tagInfo = (TagInfo) obj; + if (tagInfo.getTagName().equals(getTagName())) { + return true; + } + } + return false; + } + + @Override public int hashCode() { + return this.getTagName().hashCode(); + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public String getDisplayString() { + return getTagName(); + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagRule.java ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagRule.java b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagRule.java new file mode 100644 index 0000000..4fdce48 --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TagRule.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.syncope.ide.eclipse.plugin.editors.htmlhelpers; + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.MultiLineRule; + +public class TagRule extends MultiLineRule { + + public static final int PREFIX = 0; + public static final int NO_PREFIX = 1; + public static final int BOTH = 2; + private int prefix; + + public TagRule(final IToken token, final int prefix) { + super("<", ">", token); + this.prefix = prefix; + } + + protected boolean sequenceDetected(final ICharacterScanner scanner, + final char[] sequence, final boolean eofAllowed) { + if (sequence[0] == '<') { + int c = scanner.read(); + if (c == '?' || c == '!' || c == '%') { + scanner.unread(); + return false; + } + int back = 1; + try { + while (true) { + c = scanner.read(); + back++; + if (c == -1) { + return false; + } + if (Character.isWhitespace(c) || c == '>') { + if (prefix == PREFIX) { + return false; + } + break; + } else if (c == ':') { + if (prefix == NO_PREFIX) { + return false; + } + break; + } + } + } finally { + for (int i = 0; i < back; i++) { + scanner.unread(); + } + } + } else if (sequence[0] == '>') { + // read previous char + scanner.unread(); + scanner.unread(); + int c = scanner.read(); + // repair position + scanner.read(); + if (c == '%') { + return false; + } + } + return super.sequenceDetected(scanner, sequence, eofAllowed); + } + + protected boolean endSequenceDetected(final ICharacterScanner scanner) { + + int c; + boolean doubleQuoted = false; + boolean singleQuoted = false; + char[][] delimiters = scanner.getLegalLineDelimiters(); + boolean previousWasEscapeCharacter = false; + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (c == fEscapeCharacter) { + scanner.read(); + } else if (c == '"' && !singleQuoted) { + doubleQuoted = !doubleQuoted; + } else if (c == '\'' && !doubleQuoted) { + singleQuoted = !singleQuoted; + } else if (fEndSequence.length > 0 && c == fEndSequence[0] && !doubleQuoted + && !singleQuoted && sequenceDetected(scanner, fEndSequence, true)) { + return true; + } else if (fBreaksOnEOL) { + // Check for end of line since it can be used to terminate the pattern. + for (int i = 0; i < delimiters.length; i++) { + if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], true)) { + if (!fEscapeContinuesLine || !previousWasEscapeCharacter) { + return true; + } + } + } + } + previousWasEscapeCharacter = (c == fEscapeCharacter); + } + if (fBreaksOnEOF) { + return true; + } + scanner.unread(); + return false; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TextInfo.java ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TextInfo.java b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TextInfo.java new file mode 100644 index 0000000..7536117 --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/editors/htmlhelpers/TextInfo.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.syncope.ide.eclipse.plugin.editors.htmlhelpers; + +public class TextInfo extends TagInfo { + + private String display; + private String text; + private int position; + + public TextInfo(final String text, final int position) { + this(text, text, position); + } + + public TextInfo(final String display, final String text, final int position) { + super(null, false); + this.display = display; + this.text = text; + this.position = position; + } + + public String getDisplayString() { + return this.display; + } + + public String getText() { + return this.text; + } + + public int getPosition() { + return this.position; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/SyncopeView.java ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/SyncopeView.java b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/SyncopeView.java new file mode 100644 index 0000000..af97021 --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/SyncopeView.java @@ -0,0 +1,534 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.syncope.ide.eclipse.plugin.views; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.Scanner; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; +import org.eclipse.swt.SWT; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.client.lib.SyncopeClientFactoryBean; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.MailTemplateTO; +import org.apache.syncope.common.lib.to.ReportTemplateTO; +import org.apache.syncope.common.lib.types.ClientExceptionType; +import org.apache.syncope.common.lib.types.MailTemplateFormat; +import org.apache.syncope.common.lib.types.ReportTemplateFormat; +import org.apache.syncope.common.rest.api.service.MailTemplateService; +import org.apache.syncope.common.rest.api.service.ReportTemplateService; +import org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog; +import org.apache.syncope.ide.eclipse.plugin.dialogs.LoginDialog; +import org.apache.syncope.ide.eclipse.plugin.editors.TemplateEditor; +import org.apache.syncope.ide.eclipse.plugin.editors.TemplateEditorInput; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; + +public class SyncopeView extends ViewPart { + + public static final String ID = "org.apache.syncope.ide.eclipse.plugin.views.SyncopeView"; + + private TreeViewer viewer; + private ViewContentProvider vcp; + private static SyncopeClient SYNCOPE_CLIENT; + private Action loginAction; + private Action refreshAction; + private Action doubleClickAction; + private Action addAction; + private Action readAction; + private Action removeAction; + + private static final String MAIL_TEMPLATE_LABEL = "Mail Templates"; + private static final String REPORT_TEMPLATE_LABEL = "Report Templates"; + private static final String LOGIN_ACTION_TEXT = "Login"; + private static final String LOGIN_ACTION_TOOLTIP_TEXT = "Set Apache Syncope deployment url and login"; + private static final String REFRESH_ACTION_TEXT = "Refresh"; + private static final String REFRESH_ACTION_TOOLTIP_TEXT = "Refresh the template listings"; + private static final String READ_ACTION_TEXT = "View Template"; + private static final String ADD_ACTION_TEXT = "Add Template"; + private static final String REMOVE_ACTION_TEXT = "Remove template"; + private static final String LOADING_TEMPLATE_FORMAT_LABEL = "Loading template data"; + private static final String LOADING_TEMPLATE_LABEL = "Loading Templates"; + private static final String HELP_TEXT = "org.apache.syncope.ide.eclipse.plugin.viewer"; + public static final String TEMPLATE_FORMAT_HTML = "HTML"; + public static final String TEMPLATE_FORMAT_XSL_HTML = "XSL-HTML"; + public static final String TEMPLATE_FORMAT_CSV = "CSV"; + public static final String TEMPLATE_FORMAT_XSL_FO = "XSL-FO"; + public static final String TEMPLATE_FORMAT_TEXT = "TEXT"; + + class ViewContentProvider implements IStructuredContentProvider, ITreeContentProvider { + private TreeParent invisibleRoot; + private String deploymentUrl; + private String username; + private String password; + + ViewContentProvider() { + deploymentUrl = ""; + username = ""; + password = ""; + } + + ViewContentProvider(final String deploymentUrl, final String username, final String password) { + this.deploymentUrl = deploymentUrl; + this.username = username; + this.password = password; + } + + public void inputChanged(final Viewer v, final Object oldInput, final Object newInput) { + } + + public void dispose() { + } + + public Object[] getElements(final Object parent) { + if (parent.equals(getViewSite())) { + if (invisibleRoot == null) { + initialize(); + } + return getChildren(invisibleRoot); + } + return getChildren(parent); + } + + public Object getParent(final Object child) { + if (child instanceof TreeObject) { + return ((TreeObject) child).getParent(); + } + return null; + } + + public Object[] getChildren(final Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent) parent).getChildren(); + } + return new Object[0]; + } + + public boolean hasChildren(final Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent) parent).hasChildren(); + } + return false; + } + + public void initialize() throws java.security.AccessControlException, javax.ws.rs.ProcessingException { + invisibleRoot = new TreeParent(""); + + if (this.deploymentUrl != null && !(this.deploymentUrl.equals("")) && this.username != null + && !(this.username.equals("")) && this.password != null && !(this.password.equals(""))) { + TreeParent p1 = new TreeParent(MAIL_TEMPLATE_LABEL); + TreeParent p2 = new TreeParent(REPORT_TEMPLATE_LABEL); + + SYNCOPE_CLIENT = new SyncopeClientFactoryBean().setAddress(this.deploymentUrl).create(this.username, + this.password); + MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService(MailTemplateService.class); + List<MailTemplateTO> mailTemplateTOs = mailTemplateService.list(); + + for (int i = 0; i < mailTemplateTOs.size(); i++) { + TreeObject obj = new TreeObject(mailTemplateTOs.get(i).getKey()); + p1.addChild(obj); + } + invisibleRoot.addChild(p1); + ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class); + List<ReportTemplateTO> reportTemplateTOs = reportTemplateService.list(); + + for (int i = 0; i < reportTemplateTOs.size(); i++) { + TreeObject obj = new TreeObject(reportTemplateTOs.get(i).getKey()); + p2.addChild(obj); + } + invisibleRoot.addChild(p2); + } + } + } + + class ViewLabelProvider extends LabelProvider { + + public String getText(final Object obj) { + return obj.toString(); + } + + public Image getImage(final Object obj) { + String imageKey = ISharedImages.IMG_OBJ_ELEMENT; + if (obj instanceof TreeParent) { + imageKey = ISharedImages.IMG_OBJ_FOLDER; + } + return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); + } + } + + public void createPartControl(final Composite parent) { + viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + vcp = new ViewContentProvider(); + viewer.setContentProvider(vcp); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setSorter(new ViewerSorter()); + viewer.setInput(getViewSite()); + + // Create the help context id for the viewer's control + PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), HELP_TEXT); + makeActions(); + hookContextMenu(); + hookDoubleClickAction(); + contributeToActionBars(); + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(final IMenuManager manager) { + SyncopeView.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } + + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(final IMenuManager manager) { + manager.add(loginAction); + } + + private void fillContextMenu(final IMenuManager manager) { + + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection).getFirstElement(); + if (obj instanceof TreeParent) { + manager.add(addAction); + } else { + manager.add(readAction); + manager.add(removeAction); + } + } + + private void fillLocalToolBar(final IToolBarManager manager) { + manager.add(loginAction); + refreshAction.setEnabled(false); + manager.add(refreshAction); + } + + private void makeActions() { + loginAction = new Action() { + public void run() { + Shell shell = viewer.getControl().getShell(); + LoginDialog dialog = new LoginDialog(shell); + dialog.create(); + if (dialog.open() == Window.OK) { + String deploymentUrl = dialog.getDeploymentUrl(); + String username = dialog.getUsername(); + String password = dialog.getPassword(); + + vcp.deploymentUrl = deploymentUrl; + vcp.username = username; + vcp.password = password; + + updateTreeViewer(); + } + } + }; + loginAction.setText(LOGIN_ACTION_TEXT); + loginAction.setToolTipText(LOGIN_ACTION_TOOLTIP_TEXT); + + refreshAction = new Action() { + public void run() { + updateTreeViewer(); + } + }; + refreshAction.setText(REFRESH_ACTION_TEXT); + refreshAction.setToolTipText(REFRESH_ACTION_TOOLTIP_TEXT); + + doubleClickAction = new Action() { + public void run() { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection) selection).getFirstElement(); + if (!(obj instanceof TreeParent)) { + openTemplateInEditor((TreeObject) obj); + } else { + viewer.expandToLevel(obj, 1); + } + } + }; + + readAction = new Action() { + public void run() { + ISelection selection = viewer.getSelection(); + TreeObject obj = (TreeObject) ((IStructuredSelection) selection).getFirstElement(); + openTemplateInEditor(obj); + } + }; + readAction.setText(READ_ACTION_TEXT); + + addAction = new Action() { + public void run() { + ISelection selection = viewer.getSelection(); + TreeParent tp = (TreeParent) ((IStructuredSelection) selection).getFirstElement(); + Shell shell = viewer.getControl().getShell(); + AddTemplateDialog addTemplateDialog = new AddTemplateDialog(shell); + addTemplateDialog.create(); + if (addTemplateDialog.open() == Window.OK) { + String key = addTemplateDialog.getKey(); + try { + if (tp.getName().equals(MAIL_TEMPLATE_LABEL)) { + MailTemplateService mailTemplateService = SYNCOPE_CLIENT + .getService(MailTemplateService.class); + MailTemplateTO mtto = new MailTemplateTO(); + mtto.setKey(key); + mailTemplateService.create(mtto); + } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) { + ReportTemplateService reportTemplateService = SYNCOPE_CLIENT + .getService(ReportTemplateService.class); + ReportTemplateTO rtto = new ReportTemplateTO(); + rtto.setKey(key); + reportTemplateService.create(rtto); + } + updateTreeViewer(); + } catch (final SyncopeClientException e) { + if (e.toString().contains("EntityExists")) { + MessageDialog.openError(shell, "Template already exists", + "A template named " + key + " already exists."); + } + } + } + } + }; + addAction.setText(ADD_ACTION_TEXT); + + removeAction = new Action() { + public void run() { + ISelection selection = viewer.getSelection(); + TreeObject obj = (TreeObject) ((IStructuredSelection) selection).getFirstElement(); + TreeParent tp = (TreeParent) vcp.getParent(obj); + if (tp.getName().equals(MAIL_TEMPLATE_LABEL)) { + MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService( + MailTemplateService.class); + mailTemplateService.delete(obj.getName()); + } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) { + ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService( + ReportTemplateService.class); + reportTemplateService.delete(obj.getName()); + } + updateTreeViewer(); + } + }; + removeAction.setText(REMOVE_ACTION_TEXT); + } + + protected void openTemplateInEditor(final TreeObject obj) { + TreeParent tp = (TreeParent) vcp.getParent(obj); + if (tp.getName().equals(MAIL_TEMPLATE_LABEL)) { + final MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService( + MailTemplateService.class); + final String[] templateData = new String[2]; + final String[] editorTitles = { TEMPLATE_FORMAT_HTML, TEMPLATE_FORMAT_TEXT }; + final String[] editorToolTips = { obj.getName(), obj.getName() }; + Job job = new Job(LOADING_TEMPLATE_FORMAT_LABEL) { + @Override + protected IStatus run(final IProgressMonitor arg0) { + templateData[0] = getStringFromTemplate( + mailTemplateService, obj.getName(), MailTemplateFormat.HTML); + templateData[1] = getStringFromTemplate( + mailTemplateService, obj.getName(), MailTemplateFormat.TEXT); + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + try { + getViewSite().getPage().openEditor(new TemplateEditorInput( + templateData, editorTitles, editorToolTips), TemplateEditor.ID); + } catch (final PartInitException e) { + e.printStackTrace(); + } + } + }); + return Status.OK_STATUS; + } + private String getStringFromTemplate(final MailTemplateService mailTemplateService, + final String name, final MailTemplateFormat format) { + try { + InputStream inpstream = (InputStream) (mailTemplateService.getFormat(name, format)) + .getEntity(); + Scanner sc = new Scanner(inpstream); + String templateContent = sc.nextLine(); + while (sc.hasNext()) { + templateContent += "\n" + sc.nextLine(); + } + sc.close(); + return (templateContent); + } catch (final SyncopeClientException e) { + if (ClientExceptionType.NotFound.equals(e.getType())) { + return ""; + } + } + return null; + } + }; + job.setUser(true); + job.schedule(); + + } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) { + final ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService( + ReportTemplateService.class); + final String[] templateData = new String[3]; + final String[] editorTitles = { TEMPLATE_FORMAT_CSV, TEMPLATE_FORMAT_XSL_FO, TEMPLATE_FORMAT_XSL_HTML }; + final String[] editorToolTips = { obj.getName(), obj.getName(), obj.getName() }; + Job job = new Job(LOADING_TEMPLATE_FORMAT_LABEL) { + @Override + protected IStatus run(final IProgressMonitor arg0) { + templateData[0] = getStringFromTemplate(reportTemplateService, obj.getName(), + ReportTemplateFormat.CSV); + templateData[1] = getStringFromTemplate(reportTemplateService, obj.getName(), + ReportTemplateFormat.FO); + templateData[2] = getStringFromTemplate(reportTemplateService, obj.getName(), + ReportTemplateFormat.HTML); + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + try { + getViewSite().getPage().openEditor(new TemplateEditorInput( + templateData, editorTitles, editorToolTips), + TemplateEditor.ID); + } catch (final PartInitException e) { + e.printStackTrace(); + } + } + }); + return Status.OK_STATUS; + } + private String getStringFromTemplate(final ReportTemplateService reportTemplateService, + final String name, final ReportTemplateFormat format) { + try { + InputStream inpstream = (InputStream) (reportTemplateService.getFormat(name, format)) + .getEntity(); + Scanner sc = new Scanner(inpstream); + String templateContent = sc.nextLine(); + while (sc.hasNext()) { + templateContent += "\n" + sc.nextLine(); + } + sc.close(); + return (templateContent); + } catch (final SyncopeClientException e) { + if (ClientExceptionType.NotFound.equals(e.getType())) { + return ""; + } + } + return null; + } + }; + job.setUser(true); + job.schedule(); + } + } + + private void updateTreeViewer() { + final Display display = Display.getDefault(); + Job job = new Job(LOADING_TEMPLATE_LABEL) { + @Override + protected IStatus run(final IProgressMonitor monitor) { + try { + vcp.initialize(); + } catch (final Exception e) { + display.syncExec(new Runnable() { + public void run() { + Shell shell = viewer.getControl().getShell(); + if (e instanceof java.security.AccessControlException) { + MessageDialog.openError(shell, "Incorrect Credentials", + "Unable to authenticate " + vcp.username); + } else if (e instanceof javax.ws.rs.ProcessingException) { + MessageDialog.openError(shell, "Incorrect Url", + "Unable to find apache syncope at " + vcp.deploymentUrl); + } else if (e instanceof javax.xml.ws.WebServiceException) { + MessageDialog.openError(shell, "Invalid Url", "Not a valid url " + vcp.username); + } else { + e.printStackTrace(); + } + } + }); + } finally { + display.syncExec(new Runnable() { + public void run() { + refreshAction.setEnabled(true); + SyncopeView.this.viewer.refresh(); + } + }); + } + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + } + + private void hookDoubleClickAction() { + viewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(final DoubleClickEvent event) { + doubleClickAction.run(); + } + }); + } + + public void setFocus() { + viewer.getControl().setFocus(); + } + + public static void setMailTemplateContent(final String key, final MailTemplateFormat format, + final String content) { + MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService(MailTemplateService.class); + mailTemplateService.setFormat(key, format, new ByteArrayInputStream(content.getBytes())); + } + public static void setReportTemplateContent(final String key, final ReportTemplateFormat format, + final String content) { + ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class); + reportTemplateService.setFormat(key, format, new ByteArrayInputStream(content.getBytes())); + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeObject.java ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeObject.java b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeObject.java new file mode 100644 index 0000000..36b1a8b --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeObject.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.syncope.ide.eclipse.plugin.views; + +public class TreeObject { + private String name; + private TreeParent parent; + + TreeObject(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setParent(final TreeParent parent) { + this.parent = parent; + } + + public TreeParent getParent() { + return parent; + } + + public String toString() { + return getName(); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeParent.java ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeParent.java b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeParent.java new file mode 100644 index 0000000..d82c444 --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/java/org/apache/syncope/ide/eclipse/plugin/views/TreeParent.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.syncope.ide.eclipse.plugin.views; + +import java.util.ArrayList; +import java.util.List; + +class TreeParent extends TreeObject { + private List<TreeObject> children; + + TreeParent(final String name) { + super(name); + children = new ArrayList<TreeObject>(); + } + + public void addChild(final TreeObject child) { + children.add(child); + child.setParent(this); + } + + public void removeChild(final TreeObject child) { + children.remove(child); + child.setParent(null); + } + + public TreeObject[] getChildren() { + return (TreeObject[]) children.toArray(new TreeObject[children.size()]); + } + + public boolean hasChildren() { + return children.size() > 0; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/resources/icons/syncope.png ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/resources/icons/syncope.png b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/resources/icons/syncope.png new file mode 100644 index 0000000..0936395 Binary files /dev/null and b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/src/main/resources/icons/syncope.png differ http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/pom.xml ---------------------------------------------------------------------- diff --git a/ide/eclipse/pom.xml b/ide/eclipse/pom.xml new file mode 100644 index 0000000..e87a109 --- /dev/null +++ b/ide/eclipse/pom.xml @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.syncope</groupId> + <artifactId>syncope-ide</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <name>Apache Syncope IDE Eclipse</name> + <description>Apache Syncope IDE Eclipse</description> + <groupId>org.apache.syncope.ide</groupId> + <artifactId>syncope-ide-eclipse</artifactId> + <packaging>pom</packaging> + + <properties> + <rootpom.basedir>${basedir}/../..</rootpom.basedir> + </properties> + + <modules> + <module>bundles/org.apache.syncope.ide.eclipse.plugin</module> + <module>releng/org.apache.syncope.ide.eclipse.site</module> + </modules> + + <build> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-maven-plugin</artifactId> + <extensions>true</extensions> + </plugin> + + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>target-platform-configuration</artifactId> + <configuration> + <!-- <pomDependencies>consider</pomDependencies>--> + <environments> + <environment> + <os>linux</os> + <ws>gtk</ws> + <arch>x86</arch> + </environment> + <environment> + <os>linux</os> + <ws>gtk</ws> + <arch>x86_64</arch> + </environment> + <environment> + <os>win32</os> + <ws>win32</ws> + <arch>x86</arch> + </environment> + <environment> + <os>win32</os> + <ws>win32</ws> + <arch>x86_64</arch> + </environment> + <environment> + <os>macosx</os> + <ws>cocoa</ws> + <arch>x86_64</arch> + </environment> + </environments> + </configuration> + </plugin> + + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-p2-repository-plugin</artifactId> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>apache-release</id> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <inherited>false</inherited> + <configuration> + <skipSource>true</skipSource> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/category.xml ---------------------------------------------------------------------- diff --git a/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/category.xml b/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/category.xml new file mode 100644 index 0000000..83c846a --- /dev/null +++ b/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/category.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> +<site> + <bundle id="org.apache.syncope.ide.eclipse.plugin" version="2.0.0.qualifier"> + <category name="apachesyncope"/> + </bundle> + <category-def name="apachesyncope" label="Apache Syncope"> + <description> + Eclipse Plugin for Apache Syncope : Allows user to view and edit Mail Templates and Report Templates from Eclipse itself + </description> + </category-def> +</site> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/pom.xml ---------------------------------------------------------------------- diff --git a/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/pom.xml b/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/pom.xml new file mode 100644 index 0000000..bd34f33 --- /dev/null +++ b/ide/eclipse/releng/org.apache.syncope.ide.eclipse.site/pom.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.syncope.ide</groupId> + <artifactId>syncope-ide-eclipse</artifactId> + <version>2.0.0-SNAPSHOT</version> + <relativePath>../../</relativePath> + </parent> + + <name>Apache Syncope IDE Eclipse P2 Site</name> + <description>Apache Syncope IDE Eclipse P2 Site</description> + <groupId>org.apache.syncope.ide.eclipse</groupId> + <artifactId>org.apache.syncope.ide.eclipse.site</artifactId> + <packaging>eclipse-repository</packaging> + + <properties> + <rootpom.basedir>${basedir}/../../../..</rootpom.basedir> + </properties> + + <profiles> + <profile> + <id>apache-release</id> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <inherited>false</inherited> + <configuration> + <skipSource>true</skipSource> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/ide/pom.xml ---------------------------------------------------------------------- diff --git a/ide/pom.xml b/ide/pom.xml new file mode 100644 index 0000000..d2f1081 --- /dev/null +++ b/ide/pom.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.syncope</groupId> + <artifactId>syncope</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <name>Apache Syncope IDE</name> + <description>Apache Syncope IDE</description> + <groupId>org.apache.syncope</groupId> + <artifactId>syncope-ide</artifactId> + <packaging>pom</packaging> + + <properties> + <rootpom.basedir>${basedir}/..</rootpom.basedir> + </properties> + + <modules> + <module>eclipse</module> + </modules> + + <profiles> + <profile> + <id>apache-release</id> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <inherited>false</inherited> + <configuration> + <skipSource>true</skipSource> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/6fee50d7/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index bce0ee7..3768c3d 100644 --- a/pom.xml +++ b/pom.xml @@ -430,6 +430,7 @@ under the License. <izpack.version>5.0.9</izpack.version> <httpclient.version>4.3.6</httpclient.version> <maven-invoker.version>2.1.1</maven-invoker.version> + <tycho-version>0.23.1</tycho-version> <testds.port>1389</testds.port> <testdb.webport>9082</testdb.webport> @@ -461,6 +462,7 @@ under the License. <targetJdk>1.7</targetJdk> <rootpom.basedir>${basedir}</rootpom.basedir> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> <dependencyManagement> @@ -1333,6 +1335,11 @@ under the License. <enabled>true</enabled> </snapshots> </repository> + <repository> + <id>eclipse-mars</id> + <layout>p2</layout> + <url>http://download.eclipse.org/releases/mars/</url> + </repository> </repositories> <pluginRepositories> @@ -1547,6 +1554,23 @@ under the License. <artifactId>izpack-maven-plugin</artifactId> <version>${izpack.version}</version> </plugin> + + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-maven-plugin</artifactId> + <version>${tycho-version}</version> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>target-platform-configuration</artifactId> + <version>${tycho-version}</version> + </plugin> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-p2-repository-plugin</artifactId> + <version>${tycho-version}</version> + </plugin> </plugins> </pluginManagement> @@ -2048,6 +2072,7 @@ under the License. <module>standalone</module> <module>deb</module> <module>installer</module> + <module>ide</module> </modules> </project>
