Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed perspective and view switcher showing unlocalized strings #1250

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2018 Lablicate GmbH.
* Copyright (c) 2012, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -16,6 +16,9 @@
import javax.inject.Inject;
import javax.inject.Named;

import org.eclipse.chemclipse.rcp.app.ui.provider.SelectViewContentProvider;
import org.eclipse.chemclipse.rcp.app.ui.provider.SelectViewFilter;
import org.eclipse.chemclipse.rcp.app.ui.provider.SelectViewLabelProvider;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
Expand Down Expand Up @@ -46,10 +49,6 @@
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

import org.eclipse.chemclipse.rcp.app.ui.provider.SelectViewContentProvider;
import org.eclipse.chemclipse.rcp.app.ui.provider.SelectViewFilter;
import org.eclipse.chemclipse.rcp.app.ui.provider.SelectViewLabelProvider;

public class SelectViewDialog extends Dialog implements ISelectionChangedListener {

/*
Expand Down Expand Up @@ -82,6 +81,7 @@ public class SelectViewDialog extends Dialog implements ISelectionChangedListene

@Inject
public SelectViewDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {

super(shell);
setShellStyle(getShellStyle() | SWT.SHEET);
}
Expand All @@ -107,8 +107,8 @@ public void selectionChanged(SelectionChangedEvent event) {
int index = table.getSelectionIndex();
if(index >= 0) {
TableItem item = table.getItem(index);
if(item.getData() instanceof MPart) {
selectedPart = (MPart)item.getData();
if(item.getData() instanceof MPart part) {
selectedPart = part;
}
}
validateSelection();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2022 Lablicate GmbH.
* Copyright (c) 2012, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -31,9 +31,7 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@Override
public Object[] getElements(Object inputElement) {

if(inputElement instanceof List) {
@SuppressWarnings("rawtypes")
List perspectives = (List)inputElement;
if(inputElement instanceof List<?> perspectives) {
return perspectives.toArray();
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2022 Lablicate GmbH.
* Copyright (c) 2012, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -13,11 +13,15 @@
package org.eclipse.chemclipse.rcp.app.ui.provider;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.e4.core.services.translation.TranslationService;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ITableLabelProvider;
Expand All @@ -27,26 +31,30 @@
public class PerspectiveSwitcherLabelProvider extends LabelProvider implements ITableLabelProvider {

private static final Logger logger = Logger.getLogger(PerspectiveSwitcherLabelProvider.class);
private Map<URL, Image> imageMap = new HashMap<URL, Image>();
private Map<URI, Image> imageMap = new HashMap<>();
//
@Inject
private TranslationService translationService;

@Override
public Image getColumnImage(Object element, int columnIndex) {

Image iconImage = null;
if(columnIndex == 0 && element instanceof MPerspective) {
MPerspective perspective = (MPerspective)element;
if(columnIndex == 0 && element instanceof MPerspective perspective) {
try {
URL iconURL = new URL(perspective.getIconURI());
iconImage = imageMap.get(iconURL);
URI iconURI = new URI(perspective.getIconURI());
iconImage = imageMap.get(iconURI);
if(iconImage == null) {
/*
* Create and store the image if neccessary.
*/
iconImage = ImageDescriptor.createFromURL(iconURL).createImage();
imageMap.put(iconURL, iconImage);
iconImage = ImageDescriptor.createFromURL(iconURI.toURL()).createImage();
imageMap.put(iconURI, iconImage);
}
} catch(MalformedURLException e) {
logger.warn(e);
} catch(URISyntaxException e) {
logger.warn(e);
}
}
return iconImage;
Expand All @@ -59,8 +67,8 @@ public void dispose() {
/*
* Dispose the images and clear the map.
*/
for(URL iconURL : imageMap.keySet()) {
Image iconImage = imageMap.get(iconURL);
for(URI iconURI : imageMap.keySet()) {
Image iconImage = imageMap.get(iconURI);
if(iconImage != null) {
iconImage.dispose();
}
Expand All @@ -75,21 +83,15 @@ public String getColumnText(Object element, int columnIndex) {
* Returns the label of the perspective
*/
String text = "";
if(element instanceof MPerspective) {
MPerspective perspective = (MPerspective)element;
if(element instanceof MPerspective perspective) {
switch(columnIndex) {
case 0: // Perspective Label
text = perspective.getLabel();
if(text == null || text.equals("")) {
text = "Nameless perspective";
} else if(text.startsWith("<") && text.endsWith(">")) {
text = text.substring(1, text.length() - 1);
if(text.startsWith("%")) {
/*
* TODO - Translate
*/
text = text.substring(1, text.length());
}
text = translationService.translate(text, perspective.getContributorURI());
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2018 Lablicate GmbH.
* Copyright (c) 2012, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -12,43 +12,48 @@
package org.eclipse.chemclipse.rcp.app.ui.provider;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.e4.core.services.translation.TranslationService;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import org.eclipse.chemclipse.logging.core.Logger;

public class SelectViewLabelProvider extends LabelProvider implements ITableLabelProvider {

private static final Logger logger = Logger.getLogger(SelectViewLabelProvider.class);
private Map<URL, Image> imageMap = new HashMap<URL, Image>();
private Map<URI, Image> imageMap = new HashMap<>();
//
@Inject
private TranslationService translationService;

@Override
public Image getColumnImage(Object element, int columnIndex) {

Image iconImage = null;
if(columnIndex == 0 && element instanceof MPart) {
MPart part = (MPart)element;
if(columnIndex == 0 && element instanceof MPart part) {
try {
/*
* TODO dispose image
*/
URL iconURL = new URL(part.getIconURI());
iconImage = imageMap.get(iconURL);
URI iconURI = new URI(part.getIconURI());
iconImage = imageMap.get(iconURI);
if(iconImage == null) {
/*
* Create and store the image if neccessary.
*/
iconImage = ImageDescriptor.createFromURL(iconURL).createImage();
imageMap.put(iconURL, iconImage);
iconImage = ImageDescriptor.createFromURL(iconURI.toURL()).createImage();
imageMap.put(iconURI, iconImage);
}
} catch(MalformedURLException e) {
} catch(MalformedURLException | URISyntaxException e) {
logger.warn(e);
}
}
Expand All @@ -62,8 +67,8 @@ public void dispose() {
/*
* Dispose the images and clear the map.
*/
for(URL iconURL : imageMap.keySet()) {
Image iconImage = imageMap.get(iconURL);
for(URI iconURI : imageMap.keySet()) {
Image iconImage = imageMap.get(iconURI);
if(iconImage != null) {
iconImage.dispose();
}
Expand All @@ -78,13 +83,14 @@ public String getColumnText(Object element, int columnIndex) {
* Returns the label of the part
*/
String text = "";
if(element instanceof MPart) {
MPart part = (MPart)element;
if(element instanceof MPart part) {
switch(columnIndex) {
case 0: // Part Label
text = part.getLabel();
if(text == null || text.equals("")) {
text = "Nameless Part";
} else {
text = translationService.translate(text, part.getContributorURI());
}
break;
default:
Expand Down