use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.
the class ImageController method createControl.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl()
*/
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
// String fileName = (String) param.getValue();
// IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
// String filePath = service.getPathFileName(RepositoryConstants.IMG_DIRECTORY, fileName).toPortableString();
boolean hasScreenshots = false;
byte[] screenshot = null;
if (param.getElement() instanceof INode && ((INode) param.getElement()).getExternalNode() != null) {
String componentType = ((INode) param.getElement()).getComponent().getName();
if ("tMap".equals(componentType)) {
IProcess process = ((INode) param.getElement()).getProcess();
if (process instanceof IProcess2) {
IProcess2 processtmp = (IProcess2) process;
Item item = processtmp.getProperty().getItem();
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
screenshot = (byte[]) processItem.getProcess().getScreenshots().get(((INode) param.getElement()).getUniqueName());
if (screenshot != null) {
hasScreenshots = true;
}
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobletItem = (JobletProcessItem) item;
screenshot = (byte[]) jobletItem.getJobletProcess().getScreenshots().get(((INode) param.getElement()).getUniqueName());
if (screenshot != null) {
hasScreenshots = true;
}
}
}
}
}
if (hasScreenshots) {
ImageDescriptor imageDesc = ImageUtils.createImageFromData(screenshot);
((INode) param.getElement()).getExternalNode().setScreenshot(imageDesc);
// ImageDescriptor imageDesc = ((INode) param.getElement()).getExternalNode().getScreenshot();
// File fileOrFolder = new java.io.File(filePath);
// if (!fileOrFolder.isFile() || !fileOrFolder.canRead()) {
// return lastControl;
// }
final Composite compositeImage = new Composite(subComposite, SWT.BORDER);
final Image image = imageDesc.createImage();
addResourceDisposeListener(compositeImage, image);
//$NON-NLS-1$
CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName() + " :");
FormData formDataLabel = new FormData();
labelLabel.setVisible(true);
if (numInRow != 1) {
labelLabel.setAlignment(SWT.RIGHT);
}
if (lastControl != null) {
formDataLabel.left = new FormAttachment(lastControl, 0);
} else {
formDataLabel.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
formDataLabel.top = new FormAttachment(0, top);
}
labelLabel.setLayoutData(formDataLabel);
compositeImage.setToolTipText(param.getDisplayName());
Point size = new Point(image.getImageData().width, image.getImageData().height);
FormData formData = new FormData((int) (size.x * 0.8), (int) (size.y * 0.8));
formData.top = new FormAttachment(0, top);
formData.left = new FormAttachment(labelLabel);
ImageData data = image.getImageData();
compositeImage.setLayoutData(formData);
data = data.scaledTo((int) (size.x * 0.8), (int) (size.y * 0.8));
Image im = new Image(image.getDevice(), data);
compositeImage.setBackgroundImage(im);
return compositeImage;
} else {
return lastControl;
}
}
use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.
the class TalendEditorPaletteFactory method createComponentsDrawer.
/** Create the "Shapes" drawer. */
private static void createComponentsDrawer(final List<IComponent> componentList, final boolean needHiddenComponent, final int a, final String paletteType) {
// clearGroup();
PaletteDrawer componentsDrawer;
String name, longName;
String family;
String oraFamily;
List<CreationToolEntry> nodeList = new LinkedList<CreationToolEntry>();
List<String> families = new ArrayList<String>();
HashMap<String, String> familyMap = new HashMap<String, String>();
CombinedTemplateCreationEntry component;
Hashtable<String, PaletteDrawer> ht = new Hashtable<String, PaletteDrawer>();
List<String> favoriteComponentNames = null;
if (a == 0) {
//$NON-NLS-1$
componentsDrawer = new PaletteDrawer(Messages.getString("TalendEditorPaletteFactory.Default"));
favoriteComponentNames = getFavoritesList();
}
Set<String> displayedFamilies = ComponentsSettingsHelper.getDisplayedFamilies(paletteType);
Iterator<IComponent> componentIter = componentList.iterator();
while (componentIter.hasNext()) {
IComponent xmlComponent = componentIter.next();
if (xmlComponent.isTechnical()) {
continue;
}
// if (xmlComponent.isTechnical() || !xmlComponent.isVisible()) {
// continue;
// }
oraFamily = xmlComponent.getOriginalFamilyName();
family = xmlComponent.getTranslatedFamilyName();
if (xmlComponent.isLoaded()) {
String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
for (int j = 0; j < strings.length; j++) {
if (displayedFamilies.contains(oraStrings[j])) {
families.add(strings[j]);
familyMap.put(strings[j], oraStrings[j]);
}
}
}
}
Collections.sort(families);
List<String> recentlyUsedComponentNames = null;
List<RecentlyUsedComponent> recentlyUsedComponents = null;
if (a == 0) {
// if a==1, then means hide folder mode
recentlyUsedComponents = new LinkedList<TalendEditorPaletteFactory.RecentlyUsedComponent>();
recentlyUsedComponentNames = getRecentlyUsedList(recentlyUsedComponents);
recentlyUsedComponents = sortRecentlyUsed(recentlyUsedComponents);
families.add(0, FAVORITES);
familyMap.put(FAVORITES, FAVORITES);
families.add(1, RECENTLY_USED);
familyMap.put(RECENTLY_USED, RECENTLY_USED);
for (Object element : families) {
family = (String) element;
String oraFam = familyMap.get(family);
componentsDrawer = ht.get(family);
if (componentsDrawer == null) {
componentsDrawer = createComponentDrawer(ht, family);
// }
if (componentsDrawer instanceof IPaletteFilter) {
((IPaletteFilter) componentsDrawer).setOriginalName(oraFam);
}
}
}
}
boolean noteAeeded = false;
boolean needAddNote = true;
boolean needToAdd = false;
Map<String, IComponent> recentlyUsedMap = new HashMap<String, IComponent>();
IPreferenceStore store = DesignerPlugin.getDefault().getPreferenceStore();
String largeIconsSize = store.getString(TalendDesignerPrefConstants.LARGE_ICONS_SIZE);
componentIter = componentList.iterator();
while (componentIter.hasNext()) {
IComponent xmlComponent = componentIter.next();
if (xmlComponent.isTechnical()) {
continue;
}
family = xmlComponent.getTranslatedFamilyName();
oraFamily = xmlComponent.getOriginalFamilyName();
if (filter != null) {
String regex = getFilterRegex(filter);
//$NON-NLS-1$
needAddNote = "Note".toLowerCase().matches(regex);
}
if ((oraFamily.equals("Misc") || oraFamily.equals("Miscellaneous")) && !noteAeeded && needAddNote) {
//$NON-NLS-1$
CreationToolEntry noteCreationToolEntry = createNoteEntry(largeIconsSize);
if (a == 0) {
PaletteDrawer drawer = ht.get(family);
if (drawer != null) {
noteCreationToolEntry.setParent(drawer);
drawer.add(noteCreationToolEntry);
}
} else if (a == 1) {
for (String s : families) {
if (s.equals(family)) {
needToAdd = true;
}
}
if (needToAdd == true) {
nodeList.add(0, noteCreationToolEntry);
// noteCreationToolEntry.setParent(paGroup);
// paGroup.add(noteCreationToolEntry);
}
}
noteAeeded = true;
}
if (xmlComponent.isLoaded()) {
name = xmlComponent.getName();
longName = xmlComponent.getLongName();
ImageDescriptor imageSmall = xmlComponent.getIcon16();
ImageDescriptor imageLarge;
if (largeIconsSize.equals("24")) {
//$NON-NLS-1$
imageLarge = xmlComponent.getIcon24();
} else {
imageLarge = xmlComponent.getIcon32();
}
if (favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName())) {
componentsDrawer = ht.get(FAVORITES);
if (componentsDrawer != null) {
component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
component.setDescription(longName);
component.setParent(componentsDrawer);
componentsDrawer.add(component);
}
}
if (recentlyUsedComponentNames != null && recentlyUsedComponentNames.contains(name)) {
recentlyUsedMap.put(name, xmlComponent);
}
String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
for (int j = 0; j < strings.length; j++) {
if (!needHiddenComponent && !xmlComponent.isVisible(oraStrings[j])) {
continue;
}
component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
component.setDescription(longName);
if (a == 0) {
componentsDrawer = ht.get(strings[j]);
if (componentsDrawer == null) {
continue;
}
component.setParent(componentsDrawer);
componentsDrawer.add(component);
} else if (a == 1) {
boolean canAdd = true;
// listName = paGroup.getChildren();
// for (int z = 0; z < listName.size(); z++) {
// if ((((PaletteEntry) listName.get(z)).getLabel()).equals(component.getLabel())) {
// canAdd = false;
// }
// }
Iterator<CreationToolEntry> iter = nodeList.iterator();
while (iter.hasNext()) {
if ((iter.next().getLabel()).equals(component.getLabel())) {
canAdd = false;
}
}
if (canAdd == true) {
nodeList.add(component);
// component.setParent(paGroup);
// paGroup.add(component);
}
}
}
}
}
if (a == 0) {
createRecentlyUsedEntryList(ht, recentlyUsedComponents, recentlyUsedMap);
}
if (a == 1) {
Iterator<CreationToolEntry> iter = nodeList.iterator();
while (iter.hasNext()) {
CreationToolEntry entryCom = iter.next();
entryCom.setParent(paGroup);
paGroup.add(entryCom);
}
palette.add(paGroup);
}
}
use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.
the class TalendEditorPaletteFactory method createComponentsDrawer.
/** Create the "Shapes" drawer. */
private static void createComponentsDrawer(List<IComponent> componentList, boolean needHiddenComponent, boolean isFavorite, int a) {
clearGroup();
List<CreationToolEntry> nodeList = new LinkedList<CreationToolEntry>();
// } else if (a == 0) {
PaletteDrawer componentsDrawer;
String name, longName;
String family;
String oraFamily;
List<String> families = new ArrayList<String>();
HashMap<String, String> familyMap = new HashMap<String, String>();
// boolean favoriteFlag;
// List listName = new ArrayList();
CombinedTemplateCreationEntry component;
Hashtable<String, PaletteDrawer> ht = new Hashtable<String, PaletteDrawer>();
paletteState = isFavorite;
List<String> favoriteComponentNames = null;
if (a == 0) {
// componentsDrawer = new PaletteDrawer(Messages.getString("TalendEditorPaletteFactory.Default")); //$NON-NLS-1$
favoriteComponentNames = getFavoritesList();
}
Iterator<IComponent> componentIter = componentList.iterator();
while (componentIter.hasNext()) {
IComponent xmlComponent = componentIter.next();
if (xmlComponent.isTechnical()) {
continue;
}
oraFamily = xmlComponent.getOriginalFamilyName();
family = xmlComponent.getTranslatedFamilyName();
if (xmlComponent.isLoaded()) {
String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
for (int j = 0; j < strings.length; j++) {
if (!needHiddenComponent && !xmlComponent.isVisible(oraStrings[j])) {
continue;
}
if (a == 0) {
if (!oraStrings[j].equals("Misc")) {
//$NON-NLS-1$
if (isFavorite && !(favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName()))) {
continue;
}
}
}
families.add(strings[j]);
familyMap.put(strings[j], oraStrings[j]);
}
}
}
Collections.sort(families);
List<String> recentlyUsedComponentNames = null;
List<RecentlyUsedComponent> recentlyUsedComponents = null;
if (a == 0) {
// if a==1, then means hide folder mode
recentlyUsedComponents = new LinkedList<TalendEditorPaletteFactory.RecentlyUsedComponent>();
recentlyUsedComponentNames = getRecentlyUsedList(recentlyUsedComponents);
Collections.sort(recentlyUsedComponents, new Comparator<TalendEditorPaletteFactory.RecentlyUsedComponent>() {
@Override
public int compare(RecentlyUsedComponent arg0, RecentlyUsedComponent arg1) {
return -1 * arg0.getTimestamp().compareTo(arg1.getTimestamp());
}
});
families.add(0, FAVORITES);
familyMap.put(FAVORITES, FAVORITES);
families.add(1, RECENTLY_USED);
familyMap.put(RECENTLY_USED, RECENTLY_USED);
for (Object element : families) {
family = (String) element;
String oraFam = familyMap.get(family);
componentsDrawer = ht.get(family);
if (componentsDrawer == null) {
componentsDrawer = createComponentDrawer(ht, family);
if (componentsDrawer instanceof IPaletteFilter) {
((IPaletteFilter) componentsDrawer).setOriginalName(oraFam);
}
}
}
}
boolean noteAeeded = false;
boolean needAddNote = true;
boolean needToAdd = false;
Map<String, IComponent> recentlyUsedMap = new HashMap<String, IComponent>();
// For bug TDI-25745, to add "note" entry to Misc drawer for m/r job and common job editor. It should create
// Misc drawer first if there is not the drawer in palette.
//$NON-NLS-1$
PaletteDrawer drawer = ht.get("Miscellaneous");
if (drawer == null) {
//$NON-NLS-1$
drawer = ht.get("Misc");
if (drawer == null) {
//$NON-NLS-1$
drawer = createComponentDrawer(ht, "Misc");
if (drawer instanceof IPaletteFilter) {
//$NON-NLS-1$
((IPaletteFilter) drawer).setOriginalName("Misc");
}
}
}
IPreferenceStore store = DesignerPlugin.getDefault().getPreferenceStore();
String largeIconsSize = store.getString(TalendDesignerPrefConstants.LARGE_ICONS_SIZE);
CreationToolEntry noteCreationToolEntry = createNoteEntry(largeIconsSize);
noteCreationToolEntry.setParent(drawer);
drawer.add(noteCreationToolEntry);
componentIter = componentList.iterator();
while (componentIter.hasNext()) {
IComponent xmlComponent = componentIter.next();
if (xmlComponent.isTechnical()) {
continue;
}
family = xmlComponent.getTranslatedFamilyName();
oraFamily = xmlComponent.getOriginalFamilyName();
if (filter != null) {
//$NON-NLS-1$
Pattern pattern = Pattern.compile("^[A-Za-z0-9]+$");
Matcher matcher = pattern.matcher(filter);
if (!matcher.matches() && filter.length() != 0) {
filter = "None";
}
String regex = getFilterRegex(filter);
//$NON-NLS-1$
needAddNote = "Note".toLowerCase().matches(regex);
}
family = xmlComponent.getTranslatedFamilyName();
oraFamily = xmlComponent.getOriginalFamilyName();
// key = xmlComponent.getName() + "#" + oraKeys[j];//$NON-NLS-1$
if (isFavorite && !(favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName()))) {
continue;
}
if (xmlComponent.isLoaded()) {
name = xmlComponent.getName();
longName = xmlComponent.getLongName();
ImageDescriptor imageSmall = xmlComponent.getIcon16();
ImageDescriptor imageLarge;
if (largeIconsSize.equals("24")) {
//$NON-NLS-1$
imageLarge = xmlComponent.getIcon24();
} else {
imageLarge = xmlComponent.getIcon32();
}
if (favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName())) {
componentsDrawer = ht.get(FAVORITES);
if (componentsDrawer != null) {
component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
component.setDescription(longName);
component.setParent(componentsDrawer);
componentsDrawer.add(component);
}
}
if (recentlyUsedComponentNames != null && recentlyUsedComponentNames.contains(name)) {
recentlyUsedMap.put(name, xmlComponent);
}
if (isFavorite && !(favoriteComponentNames != null && favoriteComponentNames.contains(xmlComponent.getName()))) {
continue;
}
String[] strings = family.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
String[] oraStrings = oraFamily.split(ComponentsFactoryProvider.FAMILY_SEPARATOR_REGEX);
for (int j = 0; j < strings.length; j++) {
if (!needHiddenComponent && !xmlComponent.isVisible(oraStrings[j])) {
continue;
}
// String key = null;
// key = xmlComponent.getName() + "#" + oraStrings[j];//$NON-NLS-1$
component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, xmlComponent, imageSmall, imageLarge);
component.setDescription(longName);
if (a == 0) {
componentsDrawer = ht.get(strings[j]);
component.setParent(componentsDrawer);
componentsDrawer.add(component);
} else if (a == 1) {
boolean canAdd = true;
// listName = paGroup.getChildren();
// for (int z = 0; z < listName.size(); z++) {
// if ((((PaletteEntry) listName.get(z)).getLabel()).equals(component.getLabel())) {
// canAdd = false;
// }
// }
Iterator<CreationToolEntry> iter = nodeList.iterator();
while (iter.hasNext()) {
if ((iter.next().getLabel()).equals(component.getLabel())) {
canAdd = false;
}
}
if (canAdd == true) {
nodeList.add(component);
// component.setParent(paGroup);
// paGroup.add(component);
}
}
}
}
}
if (a == 0) {
createRecentlyUsedEntryList(ht, recentlyUsedComponents, recentlyUsedMap);
}
if (a == 1) {
Iterator<CreationToolEntry> iter = nodeList.iterator();
while (iter.hasNext()) {
CreationToolEntry entryComponent = iter.next();
entryComponent.setParent(paGroup);
paGroup.add(entryComponent);
}
palette.add(paGroup);
}
//$NON-NLS-1$
setFilter("");
}
use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.
the class TalendEditorPaletteFactory method createRecentlyUsedEntryList.
/**
* DOC cmeng Comment method "createRecentlyUsedEntry".
*
* @param componentsDrawer
* @param ht
* @param recentlyUsedList
* @param recentlyUsedMap
* @return
*/
protected static void createRecentlyUsedEntryList(Hashtable<String, PaletteDrawer> ht, List<RecentlyUsedComponent> recentlyUsedList, Map<String, IComponent> recentlyUsedMap) {
String name;
String longName;
TalendCombinedTemplateCreationEntry component;
final int recentlyUsedSize = PaletteSettingsPreferencePage.getPaletteRencentlyUsedListSize();
int i = 1;
for (RecentlyUsedComponent recentlyUsed : recentlyUsedList) {
if (recentlyUsedSize < i) {
break;
}
IComponent recentlyUsedComponent = recentlyUsedMap.get(recentlyUsed.getName());
if (recentlyUsedComponent == null) {
continue;
}
if (!ComponentUtilities.isComponentVisible(recentlyUsedComponent)) {
continue;
}
++i;
PaletteDrawer componentsDrawer = ht.get(RECENTLY_USED);
if (componentsDrawer != null) {
name = recentlyUsedComponent.getName();
longName = recentlyUsedComponent.getLongName();
ImageDescriptor imageSmall = recentlyUsedComponent.getIcon16();
IPreferenceStore store = DesignerPlugin.getDefault().getPreferenceStore();
ImageDescriptor imageLarge;
final String string = store.getString(TalendDesignerPrefConstants.LARGE_ICONS_SIZE);
if (string.equals("24")) {
//$NON-NLS-1$
imageLarge = recentlyUsedComponent.getIcon24();
} else {
imageLarge = recentlyUsedComponent.getIcon32();
}
component = new TalendCombinedTemplateCreationEntry(name, name, Node.class, recentlyUsedComponent, imageSmall, imageLarge);
component.setDescription(longName);
component.setParent(componentsDrawer);
component.setTimestemp(recentlyUsed.getTimestamp());
componentsDrawer.add(component);
}
}
}
use of org.eclipse.jface.resource.ImageDescriptor in project tdi-studio-se by Talend.
the class ComponentIconLoading method getImage32.
public ImageDescriptor getImage32() {
ImageDescriptor image32 = getImage(ComponentFilesNaming.getInstance().getIcon32FileName(folder.getName()));
registry.put(folder.getName() + "_32", image32);
return image32;
}
Aggregations