Search in sources :

Example 96 with ImageDescriptor

use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateHTMLFile.

/*
     * This method is used for generating HTML file base on an instance of <code>ExportFileResource</code> (non-Javadoc)
     * 
     * @see
     * org.talend.repository.documentation.generation.IDocumentationGenerator#generateHTMLFile(org.talend.repository
     * .documentation.ExportFileResource)
     */
@Override
public void generateHTMLFile(ExportFileResource resource, String cssFile) {
    try {
        // Store all pictures' path.
        List<URL> picList = new ArrayList<URL>(5);
        String jobName = resource.getItem().getProperty().getLabel();
        String jobVersion = resource.getItem().getProperty().getVersion();
        String tempFolderPath = checkTempDirIsExists(resource);
        handleXMLFile(resource, tempFolderPath);
        String picFolderPath = checkPicDirIsExists(resource, tempFolderPath);
        final Bundle b = Platform.getBundle(IHTMLDocConstants.REPOSITORY_PLUG_IN_ID);
        final URL xslFileUrl = FileLocator.toFileURL(FileLocator.find(b, new Path(IHTMLDocConstants.MAIN_XSL_FILE_PATH), null));
        // final URL logoFileUrl = FileLocator.toFileURL(FileLocator.find(b,
        // new Path(IHTMLDocConstants.LOGO_FILE_PATH), null));
        File logoFile = new File(picFolderPath + File.separatorChar + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
        saveLogoImage(SWT.IMAGE_JPEG, logoFile);
        String xslFilePath = xslFileUrl.getPath();
        // String logoFilePath = logoFileUrl.getPath();
        // FileCopyUtils.copy(logoFilePath, picFolderPath + File.separatorChar
        // + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
        // if import a css template, generate a new xsl file
        String temXslPath = null;
        File file = new File(xslFilePath);
        temXslPath = HTMLDocUtils.getTmpFolder() + File.separator + file.getName();
        generateXslFile(xslFilePath, temXslPath, cssFile, tempFolderPath);
        // if no new xls generated, use default xsl
        File temFile = new File(temXslPath);
        if (!temFile.exists()) {
            temXslPath = null;
        }
        if (temXslPath == null) {
            temXslPath = xslFilePath;
        }
        picList.add(logoFile.toURL());
        Set keySet = picFilePathMap.keySet();
        for (Object key : keySet) {
            String value = picFilePathMap.get(key);
            FileCopyUtils.copy(value, picFolderPath + File.separatorChar + key);
            picList.add(new File(picFolderPath + File.separatorChar + key).toURL());
        }
        byte[] innerContent = null;
        ProcessType processType = null;
        if (resource.getItem() instanceof ProcessItem) {
            processType = ((ProcessItem) resource.getItem()).getProcess();
            //$NON-NLS-1$
            innerContent = (byte[]) processType.getScreenshots().get("process");
        } else if (resource.getItem() instanceof JobletProcessItem) {
            processType = ((JobletProcessItem) resource.getItem()).getJobletProcess();
            //$NON-NLS-1$
            innerContent = (byte[]) processType.getScreenshots().get("process");
        }
        if (innerContent != null) {
            ImageDescriptor imagedesc = ImageUtils.createImageFromData(innerContent);
            //$NON-NLS-1$
            String picName = jobName + "_" + jobVersion + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
            ImageUtils.save(imagedesc.createImage(), picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
            picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
        }
        for (NodeType node : (List<NodeType>) processType.getNode()) {
            //$NON-NLS-1$
            String uniqueName = "";
            for (Object o : node.getElementParameter()) {
                if (o instanceof ElementParameterType) {
                    if ("UNIQUE_NAME".equals(((ElementParameterType) o).getName())) {
                        //$NON-NLS-1$
                        uniqueName = ((ElementParameterType) o).getValue();
                        break;
                    }
                }
            }
            byte[] screenshot = (byte[]) processType.getScreenshots().get(uniqueName);
            if (screenshot != null && screenshot.length != 0) {
                ImageDescriptor imagedesc = ImageUtils.createImageFromData(screenshot);
                String picName = IHTMLDocConstants.EXTERNAL_NODE_PREVIEW + uniqueName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
                ImageUtils.save(imagedesc.createImage(), picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
                picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
            }
        }
        //$NON-NLS-1$
        List<URL> resultFiles = parseXML2HTML(tempFolderPath, jobName + "_" + jobVersion, temXslPath);
        addResources(resource, resultFiles);
        resource.addResources(IHTMLDocConstants.PIC_FOLDER_NAME, picList);
    // List<URL> externalList = getExternalHtmlPath();
    // resource.addResources(IHTMLDocConstants.EXTERNAL_FOLDER_NAME, externalList);
    } catch (Exception e) {
        e.printStackTrace();
        ExceptionHandler.process(e);
    }
    targetConnectionMap = null;
    sourceConnectionMap = null;
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) Set(java.util.Set) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) URL(java.net.URL) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) CSSRuleList(org.w3c.dom.css.CSSRuleList) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 97 with ImageDescriptor

use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.

the class ImageUtil method getFragmentImage.

public static Image getFragmentImage(String fragmentId, String path) {
    try {
        if (path == null || path.trim().length() == 0) {
            return null;
        }
        // create image
        URL url = URLUtil.getFragmentResourceURL(fragmentId, path);
        ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
        if (descriptor == null) {
            return null;
        }
        return descriptor.createImage();
    } catch (Exception e) {
        //$NON-NLS-1$ //$NON-NLS-2$
        SqlBuilderPlugin.log(Messages.getString("ImageUtil.logMessage3") + fragmentId + ": " + path, e);
        return null;
    }
}
Also used : ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) URL(java.net.URL)

Example 98 with ImageDescriptor

use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.

the class LoginDialogV2 method createBrandingArea.

protected void createBrandingArea(Composite container) {
    brandingArea = new Composite(container, SWT.NONE);
    brandingArea.setLayout(new FormLayout());
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    ImageDescriptor imageDescriptor = brandingService.getLoginVImage();
    GridData brandingAreaGridData = new GridData(GridData.FILL_BOTH);
    if (imageDescriptor != null) {
        Image imageCanvas = imageDescriptor.createImage();
        // int width = (int) Math.ceil(realWidthRate * imageCanvas.getBounds().width);
        // maybe use the same rate for
        int width = (int) Math.ceil(realHeightRate * imageCanvas.getBounds().width);
        // image width and height is
        // better
        int height = (int) Math.ceil(realHeightRate * imageCanvas.getBounds().height);
        Image scaledImage = scaleImage(imageCanvas, width, height);
        brandingArea.setBackgroundImage(scaledImage);
        brandingAreaGridData.widthHint = scaledImage.getBounds().width;
        brandingAreaGridData.heightHint = scaledImage.getBounds().height;
    } else {
        brandingAreaGridData.widthHint = (int) Math.ceil(realWidthRate * 200);
        brandingAreaGridData.heightHint = (int) Math.ceil(realHeightRate * 280);
    }
    brandingArea.setLayoutData(brandingAreaGridData);
    errorMessageArea = new Composite(brandingArea, SWT.NONE);
    FormData formData = new FormData();
    formData.bottom = new FormAttachment(100, -5);
    formData.left = new FormAttachment(0, 5);
    formData.right = new FormAttachment(100, -5);
    errorMessageArea.setLayoutData(formData);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 10;
    layout.marginWidth = 10;
    errorMessageArea.setLayout(layout);
    errorTextLabel = new StyledText(errorMessageArea, SWT.WRAP);
    errorTextLabel.setEditable(false);
    errorTextLabel.setCaret(null);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    errorTextLabel.setLayoutData(layoutData);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) GridLayout(org.eclipse.swt.layout.GridLayout) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IBrandingService(org.talend.core.ui.branding.IBrandingService) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 99 with ImageDescriptor

use of org.eclipse.jface.resource.ImageDescriptor in project sling by apache.

the class ConvertToContentProjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IProject project = (IProject) ((IStructuredSelection) selection).getFirstElement();
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getDisplay().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
        dialog.setMessage("Select content sync root location (containing the jcr root)");
        dialog.setTitle("Content Sync Root");
        IContainer initialContainer = ProjectHelper.getInferredContentProjectContentRoot(project);
        if (initialContainer != null) {
            dialog.setInitialElementSelections(Arrays.asList(initialContainer));
        }
        dialog.addFilter(new ViewerFilter() {

            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
                if (element instanceof IProject) {
                    return ((IProject) element).equals(project);
                }
                // display folders only
                return element instanceof IContainer;
            }
        });
        dialog.setInput(new IWorkbenchAdapter() {

            @Override
            public Object getParent(Object o) {
                return null;
            }

            @Override
            public String getLabel(Object o) {
                return null;
            }

            @Override
            public ImageDescriptor getImageDescriptor(Object object) {
                return null;
            }

            @Override
            public Object[] getChildren(Object o) {
                return new Object[] { project };
            }
        });
        // this is the root element
        dialog.setAllowMultiple(false);
        dialog.setValidator(new ISelectionStatusValidator() {

            @Override
            public IStatus validate(Object[] selection) {
                if (selection.length > 0) {
                    final Object item = selection[0];
                    if (item instanceof IContainer) {
                        IContainer selectedContainer = (IContainer) item;
                        String errorMsg = ProjectHelper.validateContentPackageStructure(selectedContainer);
                        if (errorMsg != null) {
                            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMsg);
                        } else {
                            return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
                        }
                    }
                }
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "");
            }
        });
        if (dialog.open() == ContainerSelectionDialog.OK) {
            Object[] result = dialog.getResult();
            if (result != null && result.length > 0) {
                final IContainer container = (IContainer) result[0];
                IRunnableWithProgress r = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            IResource jcrRoot = container.findMember("jcr_root");
                            if (jcrRoot == null || !(jcrRoot instanceof IFolder)) {
                                MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", "jcr_root not found under " + container + " (or not a Folder)");
                                return;
                            }
                            ConfigurationHelper.convertToContentPackageProject(project, monitor, jcrRoot.getProjectRelativePath());
                        } catch (CoreException e) {
                            Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                            MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                        }
                    }
                };
                try {
                    PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
                } catch (Exception e) {
                    Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                    MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                }
            }
        }
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) BaseWorkbenchContentProvider(org.eclipse.ui.model.BaseWorkbenchContentProvider) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) ISelection(org.eclipse.jface.viewers.ISelection) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 100 with ImageDescriptor

use of org.eclipse.jface.resource.ImageDescriptor in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method initToolbarContributedActions.

private void initToolbarContributedActions() {
    cleanAction = new Action("Clean Publish...", IAction.AS_PUSH_BUTTON) {

        public void run() {
            if (server == null) {
                MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
                return;
            }
            int selection = 2;
            if (!doNotAskAgain) {
                MessageDialog dialog = new MessageDialog(view.getSite().getShell(), Messages.defaultDialogTitle, null, Messages.dialogPublishClean, MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "OK (do not ask again)", "OK" }, 1) {

                    @Override
                    protected void configureShell(Shell shell) {
                        super.configureShell(shell);
                        setShellStyle(getShellStyle() | SWT.SHEET);
                    }
                };
                selection = dialog.open();
            }
            if (selection != 0) {
                if (selection == 1) {
                    doNotAskAgain = true;
                }
                IAdaptable info = new IAdaptable() {

                    public Object getAdapter(Class adapter) {
                        if (Shell.class.equals(adapter))
                            return view.getSite().getShell();
                        if (String.class.equals(adapter))
                            return "user";
                        return null;
                    }
                };
                server.publish(IServer.PUBLISH_CLEAN, modules, info, null);
            }
        }
    };
    cleanAction.setText("Clean Publish...");
    cleanAction.setToolTipText("Clean and Publish...");
    ImageDescriptor cleanAndPublishImageDesc = new DecorationOverlayIcon(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH).createImage(), ImageDescriptor.createFromFile(SharedImages.class, "refresh.gif"), IDecoration.BOTTOM_RIGHT);
    cleanAction.setImageDescriptor(cleanAndPublishImageDesc);
    cleanAction.setId("org.apache.sling.ide.eclipse.ui.actions.CleanPublishAction");
    publishAction = new Action("Publish", IAction.AS_PUSH_BUTTON) {

        public void run() {
            if (server == null) {
                MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
                return;
            }
            IAdaptable info = new IAdaptable() {

                public Object getAdapter(Class adapter) {
                    if (Shell.class.equals(adapter))
                        return view.getSite().getShell();
                    if (String.class.equals(adapter))
                        return "user";
                    return null;
                }
            };
            server.publish(IServer.PUBLISH_INCREMENTAL, modules, info, null);
        }
    };
    publishAction.setText("Publish");
    publishAction.setToolTipText("Publish");
    publishAction.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH));
    publishAction.setId("org.apache.sling.ide.eclipse.ui.actions.PublishAction");
    cleanAction.setEnabled(false);
    publishAction.setEnabled(false);
    cleanActionContributionItem = new ActionContributionItem(cleanAction);
    publishActionContributionItem = new ActionContributionItem(publishAction);
    appendedToolbarActionContributionItems.add(publishActionContributionItem);
    appendedToolbarActionContributionItems.add(cleanActionContributionItem);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Shell(org.eclipse.swt.widgets.Shell) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Aggregations

ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)106 Image (org.eclipse.swt.graphics.Image)25 ArrayList (java.util.ArrayList)21 List (java.util.List)18 ToolEntry (org.eclipse.gef.palette.ToolEntry)14 URL (java.net.URL)12 ImageData (org.eclipse.swt.graphics.ImageData)11 ResourceImageDescriptor (de.jaret.util.ui.ResourceImageDescriptor)9 Point (org.eclipse.swt.graphics.Point)6 Node (org.talend.designer.core.ui.editor.nodes.Node)6 Path (org.eclipse.core.runtime.Path)5 JavaElementImageDescriptor (org.eclipse.jdt.ui.JavaElementImageDescriptor)5 File (java.io.File)4 HashMap (java.util.HashMap)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 IComponent (org.talend.core.model.components.IComponent)4 INode (org.talend.core.model.process.INode)4 MalformedURLException (java.net.MalformedURLException)3 Set (java.util.Set)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3