use of org.eclipse.e4.core.services.translation.TranslationService in project aero.minova.rcp by minova-afis.
the class WFCDetailPart method postConstruct.
@PostConstruct
public void postConstruct(Composite parent, MWindow window, MApplication mApp) {
resManager = new LocalResourceManager(JFaceResources.getResources(), parent);
composite = parent;
formToolkit = new FormToolkit(parent.getDisplay());
appContext = mApp.getContext();
mApplication = mApp;
getForm();
layoutForm(parent);
mDetail.setDetailAccessor(new DetailAccessor(mDetail));
mDetail.setClearAfterSave(form.getDetail().isClearAfterSave());
// Erstellen der Util-Klasse, welche sämtliche funktionen der Detailansicht steuert
casRequestsUtil = ContextInjectionFactory.make(WFCDetailCASRequestsUtil.class, mPerspective.getContext());
casRequestsUtil.initializeCasRequestUtil(getDetail(), mPerspective, this);
mPerspective.getContext().set(WFCDetailCASRequestsUtil.class, casRequestsUtil);
mPerspective.getContext().set(Constants.DETAIL_WIDTH, detailWidth);
TranslateUtil.translate(composite, translationService, locale);
// Helper erst initialisieren, wenn casRequestsUtil erstellt wurde
if (mDetail.getHelper() != null) {
mDetail.getHelper().setControls(mDetail);
}
// Handler, der Dialog anzeigt wenn versucht wird, die Anwendung mit ungespeicherten Änderungen zu schließen. Außerdem wird
// "RESTORING_UI_MESSAGE_SHOWN_THIS_SESSION" wieder auf false gesetzt, damit die Nachricht beim nächsten Starten wieder angezeigt wird
IWindowCloseHandler handler = mWindow -> {
@SuppressWarnings("unchecked") List<MPerspective> pList = (List<MPerspective>) appContext.get(Constants.DIRTY_PERSPECTIVES);
if (pList != null && !pList.isEmpty()) {
StringBuilder listString = new StringBuilder();
for (MPerspective mPerspective : pList) {
listString.append(" - " + translationService.translate(mPerspective.getLabel(), null) + "\n");
}
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), translationService.translate("@msg.ChangesDialog", null), null, translationService.translate("@msg.Close.DirtyMessage", null) + listString, MessageDialog.CONFIRM, new String[] { translationService.translate("@Action.Discard", null), translationService.translate("@Abort", null) }, 0);
boolean res = dialog.open() == 0;
if (res) {
prefs.put(Constants.RESTORING_UI_MESSAGE_SHOWN_THIS_SESSION, "false");
}
return res;
}
prefs.put(Constants.RESTORING_UI_MESSAGE_SHOWN_THIS_SESSION, "false");
return true;
};
window.getContext().set(IWindowCloseHandler.class, handler);
openRestoringUIDialog();
}
use of org.eclipse.e4.core.services.translation.TranslationService in project aero.minova.rcp by minova-afis.
the class PerspectiveControl method createGui.
/*
* Create the ToolControl with a Toolbar for the Perspective Shortcuts
*/
@PostConstruct
public void createGui(Composite parent, MWindow window) {
composite = new Composite(parent, SWT.BAR);
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
composite.setLayout(rowLayout);
resManager = new LocalResourceManager(JFaceResources.getResources(), composite);
toolBar = new ToolBar(composite, SWT.FLAT | SWT.WRAP | SWT.RIGHT);
toolBar.addMenuDetectListener(event -> {
ToolBar tb = (ToolBar) event.widget;
Point p = new Point(event.x, event.y);
p = toolBar.getDisplay().map(null, toolBar, p);
ToolItem item = tb.getItem(p);
if (item != null && item.getData() != null) {
openMenuFor(item, (String) item.getData());
} else {
logger.debug("No item found or item is null");
}
});
List<String> oldToolbarOrder = readOldToolbarOrder();
openToolbarItems = new ArrayList<>();
// Perspektiven der vorherigen Session wiederherstellen
for (String id : oldToolbarOrder) {
if (id.isBlank()) {
continue;
}
List<MPerspective> perspectives = modelService.findElements(window, id, MPerspective.class);
if (!perspectives.isEmpty()) {
// Perspektive war geöffnet
MPerspective perspective = perspectives.get(0);
if (perspective.isToBeRendered()) {
addPerspectiveShortcut(//
perspective.getElementId(), //
perspective.getPersistedState().get(Constants.FORM_NAME), //
perspective.getLabel(), //
perspective.getIconURI(), //
perspective.getLocalizedLabel(), //
perspective.getLocalizedTooltip(), true);
}
if (perspective == modelService.getActivePerspective(window)) {
setSelectedElement(perspective);
}
} else if (!prefsKeptPerspectives.get(id + Constants.KEPT_PERSPECTIVE_FORMNAME, "").equals("")) {
// Perspektive war angeheftet
addPerspectiveShortcut(//
id, //
prefsKeptPerspectives.get(id + Constants.KEPT_PERSPECTIVE_FORMNAME, ""), //
prefsKeptPerspectives.get(id + Constants.KEPT_PERSPECTIVE_FORMLABEL, ""), //
prefsKeptPerspectives.get(id + Constants.KEPT_PERSPECTIVE_ICONURI, ""), //
prefsKeptPerspectives.get(id + Constants.KEPT_PERSPECTIVE_LOCALIZEDLABEL, ""), //
prefsKeptPerspectives.get(id + Constants.KEPT_PERSPECTIVE_LOCALIZEDTOOLTIP, ""), true);
}
}
translate(translationService);
}
use of org.eclipse.e4.core.services.translation.TranslationService in project aero.minova.rcp by minova-afis.
the class PrintIndexHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) List<Row> rows, MPart mpart, MWindow window, EModelService modelService, EPartService partService) {
String xmlRootTag = null;
String title = null;
Object o = mpart.getObject();
StringBuffer xml = new StringBuffer();
MPerspective activePerspective = modelService.getActivePerspective(window);
title = translationService.translate(activePerspective.getLabel(), null);
Path path_reports = dataService.getStoragePath().resolve("pdf/");
String xslString = null;
if (o instanceof WFCIndexPart) {
WFCIndexPart indexPart = (WFCIndexPart) o;
Table data = indexPart.getData();
xmlRootTag = data.getName();
SortedList<Row> sortedDataList = indexPart.getSortedList();
ColumnReorderLayer columnReorderLayer = indexPart.getBodyLayerStack().getColumnReorderLayer();
columnReorderLayer.getColumnIndexOrder();
// Gruppierung
TreeList<Row> treeList = indexPart.getBodyLayerStack().getBodyDataLayer().getTreeList();
List<Integer> groupByIndices = indexPart.getGroupByHeaderLayer().getGroupByModel().getGroupByColumnIndexes();
List<Integer> groupByIndicesReordered = new ArrayList<>();
// Optimalen Spaltenbreiten ermitteln
int[] widths = new int[columnReorderLayer.getColumnCount()];
if (optimizeWidths) {
for (int i = 0; i < widths.length; i++) {
widths[i] = i;
}
// Hier wird die optimale Breite für Spalten aufgrund des Tabellen-Körpers ermittelt. Aufgrund der extremen Länge einzelner Spalten die durch
// Gruppierung zustande kommt wird hier der GlazedListsEventLayer verwendet, der die Gruppierungs-Zeilen nicht enthält
ILayer layer = indexPart.getBodyLayerStack().getGlazedListsEventLayer();
int[] widthsBody = MaxCellBoundsHelper.getPreferredColumnWidths(indexPart.getNattable().getConfigRegistry(), new GCFactory(indexPart.getNattable()), layer, widths);
// Hier wird die optimale Breite für Spalten aufgrund des Headers ermittelt
layer = indexPart.getColumnHeaderDataLayer();
int[] widthsHeader = MaxCellBoundsHelper.getPreferredColumnWidths(indexPart.getNattable().getConfigRegistry(), new GCFactory(indexPart.getNattable()), layer, widths);
// Die Breite einer Spalte ist das Maximum der Header und Body Breite
for (int i = 0; i < widths.length; i++) {
widths[i] = Math.max(widthsBody[i], widthsHeader[i]);
}
}
// ColumnInfo erstellen
List<ColumnInfo> colConfig = new ArrayList<>();
int i = 0;
for (Integer i1 : columnReorderLayer.getColumnIndexOrder()) {
int width = columnReorderLayer.getColumnWidthByPosition(i);
if (optimizeWidths) {
width = widths[i1];
}
boolean vis = !hideEmptyCols || !isColumnEmpty(i1, sortedDataList);
colConfig.add(new ColumnInfo(data.getColumns().get(i1), width, vis, i));
if (groupByIndices.contains(i1)) {
groupByIndicesReordered.add(i);
}
i++;
}
ReportConfiguration rConfig = new ReportConfiguration();
if (indexFont != null && !indexFont.isEmpty()) {
FontData fontData = new FontData(indexFont);
int fontsize = 8;
try {
fontsize = fontData.getHeight();
} catch (Exception e) {
}
rConfig.setProp("FontSizeCriteria", fontsize + "");
rConfig.setProp("FontSizeCell", fontsize + "");
rConfig.setProp("FontFamily", fontData.getName());
rConfig.guiFont = new Font(fontData.getName(), Font.PLAIN, fontsize);
}
try {
TableXSLCreator tableCreator = new TableXSLCreator(translationService, this, ePartService);
xslString = tableCreator.createXSL(xmlRootTag, title, colConfig, rConfig, path_reports, groupByIndicesReordered);
} catch (ReportCreationException e) {
e.printStackTrace();
}
createXML(indexPart, treeList, groupByIndices, colConfig, columnReorderLayer.getColumnIndexOrder(), xml, false, xmlRootTag, title);
try {
Path pathPDF = dataService.getStoragePath().resolve("outputReports/" + title + "_Index.pdf");
Files.createDirectories(pathPDF.getParent());
pathPDF = Path.of(FileUtil.createFile(pathPDF.toString()));
URL urlPDF = pathPDF.toFile().toURI().toURL();
Path pathXML = dataService.getStoragePath().resolve("pdf/" + xmlRootTag + "_Index.xml");
Path pathXSL = dataService.getStoragePath().resolve("pdf/" + xmlRootTag + "_Index.xsl");
pathXML = Path.of(FileUtil.createFile(pathXML.toString()));
pathXSL = Path.of(FileUtil.createFile(pathXSL.toString()));
IOUtil.saveLoud(xml.toString(), pathXML.toString(), "UTF-8");
IOUtil.saveLoud(xslString, pathXSL.toString(), "UTF-8");
// Wenn ein file schon geladen wurde muss dieses erst freigegeben werden (unter Windows)
if (!disablePreview) {
PrintUtil.checkPreview(activePerspective, modelService, partService);
}
urlPDF = PrintUtil.generatePDF(urlPDF, xml.toString(), pathXSL.toFile());
if (!createXmlXsl) {
Files.delete(pathXSL);
Files.delete(pathXML);
}
if (disablePreview) {
PrintUtil.showFile(urlPDF.toString(), null);
} else {
PrintUtil.showFile(urlPDF.toString(), PrintUtil.checkPreview(activePerspective, modelService, partService));
}
} catch (IOException | SAXException | TransformerException e) {
e.printStackTrace();
ShowErrorDialogHandler.execute(Display.getCurrent().getActiveShell(), translationService.translate("@Error", null), translationService.translate("@msg.ErrorShowingFile", null), e);
}
}
}
use of org.eclipse.e4.core.services.translation.TranslationService in project aero.minova.rcp by minova-afis.
the class ApplicationPreferenceWindowHandler method execute.
@Execute
public void execute(IThemeEngine themeEngine, IWorkbench workbench, IEclipseContext context) {
pwm = new PreferenceWindowModel(s);
// In Context injected, damit TranslationService genutzt werden kann
ContextInjectionFactory.inject(pwm, application.getContext());
this.workbench = workbench;
// Shell des Windows der Application finden
MWindow appWindow = application.getChildren().get(0);
Shell shell = (Shell) appWindow.getWidget();
// Die Shell des Windows deaktivieren
shell.setEnabled(false);
String currentTheme = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.FONT_ICON_SIZE, DisplayType.COMBO, "M", s);
boolean curentSelectAllControls = (boolean) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.SELECT_ALL_CONTROLS, DisplayType.CHECK, true, s);
List<PreferenceTabDescriptor> preferenceTabs = pwm.createModel(context);
Map<String, Object> data = fillData(preferenceTabs);
PreferenceWindow window = PreferenceWindow.create(shell, data);
for (PreferenceTabDescriptor tabDescriptor : preferenceTabs) {
// Tab erstellen und hinzufügen
PWTab newTab = window.addTab(tabDescriptor.getImage(), tabDescriptor.getLabel());
for (PreferenceSectionDescriptor section : tabDescriptor.getSections()) {
// Section hinzufügen
newTab.add(new PWSeparator(section.getLabel()));
for (PreferenceDescriptor pref : section.getPreferences()) {
// Preference hinzufügen
Object[] values = pref.getPossibleValues();
String key = pref.getKey();
createWidgets(newTab, pref, key, translationService, values);
}
}
}
// Preference Handler finden
List<MHandler> preferenceHandlers = modelService.findElements(application, "aero.minova.rcp.rcp.handler.preferencehandler", MHandler.class);
MHandler preferenceHandler = preferenceHandlers.get(0);
// Preference Handler deaktivieren
handlerService.deactivateHandler("org.eclipse.ui.window.preferences", preferenceHandler.getObject());
window.setSelectedTab(0);
if (window.open()) {
InstancePreferenceAccessor.putValue(preferences, ApplicationPreferences.TIMEZONE, DisplayType.ZONEID, window.getValueFor(ApplicationPreferences.TIMEZONE), s);
InstancePreferenceAccessor.putValue(preferences, ApplicationPreferences.LOCALE_LANGUAGE, DisplayType.LOCALE, window.getValueFor(ApplicationPreferences.LOCALE_LANGUAGE), s);
InstancePreferenceAccessor.putValue(preferences, ApplicationPreferences.COUNTRY, DisplayType.LOCALE, window.getValueFor(ApplicationPreferences.COUNTRY), s);
for (PreferenceTabDescriptor tab : preferenceTabs) {
for (PreferenceSectionDescriptor section : tab.getSections()) {
for (PreferenceDescriptor pref : section.getPreferences()) {
if (pref.getDisplayType() != DisplayType.ZONEID && pref.getDisplayType() != DisplayType.CUSTOMCHECK) {
InstancePreferenceAccessor.putValue(preferences, pref.getKey(), pref.getDisplayType(), window.getValueFor(pref.getKey()), s);
}
}
}
}
try {
preferences.flush();
lcs.changeApplicationLocale(CustomLocale.getLocale());
} catch (BackingStoreException | NullPointerException e) {
e.printStackTrace();
}
}
if (Util.isValid(shell)) {
// Die Shell des Windows aktivieren
shell.setEnabled(true);
// Preference Handler wieder aktivieren
handlerService.activateHandler("org.eclipse.ui.window.preferences", preferenceHandler.getObject());
}
boolean newSelectAllControls = (boolean) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.SELECT_ALL_CONTROLS, DisplayType.CHECK, true, s);
String newTheme = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.FONT_ICON_SIZE, DisplayType.COMBO, "M", s);
if (!currentTheme.equals(newTheme) || !curentSelectAllControls == newSelectAllControls) {
Shell activeShell = Display.getCurrent().getActiveShell();
PlainMessageDialog confirmRestart = getBuilder(activeShell, translationService.translate("@Action.Restart", null)).buttonLabels(List.of(translationService.translate("@Action.Restart", null), translationService.translate("@Abort", null))).message(translationService.translate("@Preferences.RestartMessage", null)).build();
int openConfirm = confirmRestart.open();
if (openConfirm == 0) {
if (!currentTheme.equals(newTheme)) {
updateTheme(newTheme, themeEngine, workbench);
} else {
workbench.restart();
}
}
}
}
use of org.eclipse.e4.core.services.translation.TranslationService in project aero.minova.rcp by minova-afis.
the class DateTimeField method create.
public static Control create(Composite composite, MField field, int row, int column, Locale locale, String timezone, MPerspective perspective, TranslationService translationService) {
Preferences preferences = InstanceScope.INSTANCE.getNode(ApplicationPreferences.PREFERENCES_NODE);
String dateUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.DATE_UTIL, DisplayType.DATE_UTIL, "", locale);
String timeUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.TIME_UTIL, DisplayType.TIME_UTIL, "", locale);
Label label = FieldLabel.create(composite, field);
TextAssistContentProvider contentProvider = new TextAssistContentProvider() {
@Override
public List<String> getContent(String entry) {
ArrayList<String> result = new ArrayList<>();
Instant date = DateTimeUtil.getDateTime(Instant.now(), entry, locale);
if (date == null && !entry.isEmpty()) {
result.add(translationService.translate("@msg.ErrorConverting", null));
} else {
result.add(DateTimeUtil.getDateTimeString(date, locale, dateUtil, timeUtil));
field.setValue(new Value(date), true);
}
return result;
}
};
TextAssist text = new TextAssist(composite, SWT.BORDER, contentProvider);
LocalDateTime of = LocalDateTime.of(LocalDate.of(2020, 12, 12), LocalTime.of(22, 55));
text.setMessage(DateTimeUtil.getDateTimeString(of.toInstant(ZoneOffset.UTC), locale, dateUtil, timeUtil));
text.setNumberOfLines(1);
text.setData(TRANSLATE_LOCALE, locale);
text.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
text.selectAll();
}
@Override
public void focusLost(FocusEvent e) {
if (text.getText().isBlank()) {
field.setValue(null, true);
}
}
});
text.setData(Constants.CONTROL_FIELD, field);
// ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
IEclipseContext context = perspective.getContext();
DateTimeValueAccessor valueAccessor = new DateTimeValueAccessor(field, text);
ContextInjectionFactory.inject(valueAccessor, context);
field.setValueAccessor(valueAccessor);
FormData fd = new FormData();
fd.top = new FormAttachment(composite, MARGIN_TOP + row * COLUMN_HEIGHT);
fd.left = new FormAttachment(column == 0 ? 25 : 75);
fd.right = new FormAttachment(column == 0 ? 50 : 100, column == 0 ? -ICssStyler.CSS_SECTION_SPACING : -MARGIN_BORDER);
text.setLayoutData(fd);
text.setData(CssData.CSSDATA_KEY, new CssData(CssType.DATE_TIME_FIELD, column + 1, row, field.getNumberColumnsSpanned(), field.getNumberRowsSpanned(), false));
FieldLabel.layout(label, text, row, column, field.getNumberRowsSpanned());
return text;
}
Aggregations