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;
}
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;
}
}
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);
}
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;
}
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);
}
Aggregations