Search in sources :

Example 1 with TranslationService

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();
}
Also used : ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) MLookupField(aero.minova.rcp.model.form.MLookupField) MinovaSection(aero.minova.rcp.css.widgets.MinovaSection) Point(org.eclipse.swt.graphics.Point) ValueChangeListener(aero.minova.rcp.model.event.ValueChangeListener) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IWindowCloseHandler(org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) MButton(aero.minova.rcp.model.form.MButton) ServiceReference(org.osgi.framework.ServiceReference) ValueChangeEvent(aero.minova.rcp.model.event.ValueChangeEvent) MApplication(org.eclipse.e4.ui.model.application.MApplication) MGrid(aero.minova.rcp.model.form.MGrid) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Constants(aero.minova.rcp.constants.Constants) Node(aero.minova.rcp.form.setup.xbs.Node) LookupField(aero.minova.rcp.rcp.fields.LookupField) WFCDetailCASRequestsUtil(aero.minova.rcp.rcp.util.WFCDetailCASRequestsUtil) ToolItem(org.eclipse.swt.widgets.ToolItem) MouseEvent(org.eclipse.swt.events.MouseEvent) IHelper(aero.minova.rcp.model.helper.IHelper) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Item(org.eclipse.swt.widgets.Item) MenuItem(org.eclipse.swt.widgets.MenuItem) Page(aero.minova.rcp.form.model.xsd.Page) SWT(org.eclipse.swt.SWT) MTextField(aero.minova.rcp.model.form.MTextField) SelectionListener(org.eclipse.swt.events.SelectionListener) MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) UIEventTopic(org.eclipse.e4.ui.di.UIEventTopic) TranslationService(org.eclipse.e4.core.services.translation.TranslationService) ECommandService(org.eclipse.e4.core.commands.ECommandService) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) MCommand(org.eclipse.e4.ui.model.application.commands.MCommand) JFaceResources(org.eclipse.jface.resource.JFaceResources) ButtonAccessor(aero.minova.rcp.rcp.accessor.ButtonAccessor) ControlListener(org.eclipse.swt.events.ControlListener) MToolBarElement(org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) ModelToViewModel(aero.minova.rcp.model.form.ModelToViewModel) Named(javax.inject.Named) Section(org.eclipse.ui.forms.widgets.Section) Onclick(aero.minova.rcp.form.model.xsd.Onclick) MParameter(org.eclipse.e4.ui.model.application.commands.MParameter) Procedure(aero.minova.rcp.form.model.xsd.Procedure) SectionAccessor(aero.minova.rcp.rcp.accessor.SectionAccessor) Shell(org.eclipse.swt.widgets.Shell) ShortDateField(aero.minova.rcp.rcp.fields.ShortDateField) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) FormLayout(org.eclipse.swt.layout.FormLayout) MHandledItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledItem) DateTimeField(aero.minova.rcp.rcp.fields.DateTimeField) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ExecutionException(java.util.concurrent.ExecutionException) Preference(org.eclipse.e4.core.di.extensions.Preference) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Form(aero.minova.rcp.form.model.xsd.Form) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ContextInjectionFactory(org.eclipse.e4.core.contexts.ContextInjectionFactory) Head(aero.minova.rcp.form.model.xsd.Head) MDetail(aero.minova.rcp.model.form.MDetail) TabUtil(aero.minova.rcp.rcp.util.TabUtil) ToolBar(org.eclipse.swt.widgets.ToolBar) MBooleanField(aero.minova.rcp.model.form.MBooleanField) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) MNumberField(aero.minova.rcp.model.form.MNumberField) Wizard(aero.minova.rcp.form.model.xsd.Wizard) Preferences(aero.minova.rcp.form.setup.xbs.Preferences) EHandlerService(org.eclipse.e4.core.commands.EHandlerService) GridChangeEvent(aero.minova.rcp.model.event.GridChangeEvent) Locale(java.util.Locale) MField(aero.minova.rcp.model.form.MField) Column(aero.minova.rcp.model.Column) MDateTimeField(aero.minova.rcp.model.form.MDateTimeField) Optional(org.eclipse.e4.core.di.annotations.Optional) Display(org.eclipse.swt.widgets.Display) JAXBException(javax.xml.bind.JAXBException) BundleContext(org.osgi.framework.BundleContext) NumberField(aero.minova.rcp.rcp.fields.NumberField) MShortDateField(aero.minova.rcp.model.form.MShortDateField) List(java.util.List) IWorkbench(org.eclipse.e4.ui.workbench.IWorkbench) GridChangeListener(aero.minova.rcp.model.event.GridChangeListener) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) MouseAdapter(org.eclipse.swt.events.MouseAdapter) PersistState(org.eclipse.e4.ui.di.PersistState) ShortTimeField(aero.minova.rcp.rcp.fields.ShortTimeField) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SectionGrid(aero.minova.rcp.rcp.widgets.SectionGrid) TRANSLATE_PROPERTY(aero.minova.rcp.rcp.fields.FieldUtil.TRANSLATE_PROPERTY) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) XBSUtil(aero.minova.rcp.form.setup.util.XBSUtil) ImageUtil(aero.minova.rcp.dataservice.ImageUtil) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) Inject(javax.inject.Inject) DetailLayout(aero.minova.rcp.css.widgets.DetailLayout) MinovaSectionData(aero.minova.rcp.css.widgets.MinovaSectionData) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MHandledToolItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) MSection(aero.minova.rcp.model.form.MSection) TextField(aero.minova.rcp.rcp.fields.TextField) Field(aero.minova.rcp.form.model.xsd.Field) TranslateUtil(aero.minova.rcp.rcp.util.TranslateUtil) MParamStringField(aero.minova.rcp.model.form.MParamStringField) FieldUtil(aero.minova.rcp.rcp.fields.FieldUtil) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) MTrimBar(org.eclipse.e4.ui.model.application.ui.basic.MTrimBar) UISynchronize(org.eclipse.e4.ui.di.UISynchronize) GridAccessor(aero.minova.rcp.rcp.accessor.GridAccessor) XmlProcessor(aero.minova.rcp.dataservice.XmlProcessor) MShortTimeField(aero.minova.rcp.model.form.MShortTimeField) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Grid(aero.minova.rcp.form.model.xsd.Grid) DetailAccessor(aero.minova.rcp.rcp.accessor.DetailAccessor) BooleanField(aero.minova.rcp.rcp.fields.BooleanField) FrameworkUtil(org.osgi.framework.FrameworkUtil) Control(org.eclipse.swt.widgets.Control) DetailAccessor(aero.minova.rcp.rcp.accessor.DetailAccessor) MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) WFCDetailCASRequestsUtil(aero.minova.rcp.rcp.util.WFCDetailCASRequestsUtil) ArrayList(java.util.ArrayList) List(java.util.List) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IWindowCloseHandler(org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler) PostConstruct(javax.annotation.PostConstruct)

Example 2 with TranslationService

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);
}
Also used : MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) Composite(org.eclipse.swt.widgets.Composite) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) RowLayout(org.eclipse.swt.layout.RowLayout) ToolBar(org.eclipse.swt.widgets.ToolBar) Point(org.eclipse.swt.graphics.Point) ToolItem(org.eclipse.swt.widgets.ToolItem) PostConstruct(javax.annotation.PostConstruct)

Example 3 with 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);
        }
    }
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) TableXSLCreator(aero.minova.rcp.rcp.print.TableXSLCreator) ArrayList(java.util.ArrayList) ColumnInfo(aero.minova.rcp.rcp.print.ColumnInfo) ReportCreationException(aero.minova.rcp.rcp.print.ReportCreationException) Font(java.awt.Font) URL(java.net.URL) SAXException(org.xml.sax.SAXException) MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) WFCIndexPart(aero.minova.rcp.rcp.parts.WFCIndexPart) TransformerException(javax.xml.transform.TransformerException) Path(java.nio.file.Path) Table(aero.minova.rcp.model.Table) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) FontData(org.eclipse.swt.graphics.FontData) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) IOException(java.io.IOException) ReportCreationException(aero.minova.rcp.rcp.print.ReportCreationException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Row(aero.minova.rcp.model.Row) ReportConfiguration(aero.minova.rcp.rcp.print.ReportConfiguration) Execute(org.eclipse.e4.core.di.annotations.Execute) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 4 with TranslationService

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();
            }
        }
    }
}
Also used : PlainMessageDialog(org.eclipse.jface.dialogs.PlainMessageDialog) PreferenceWindow(org.eclipse.nebula.widgets.opal.preferencewindow.PreferenceWindow) MHandler(org.eclipse.e4.ui.model.application.commands.MHandler) PreferenceWindowModel(aero.minova.rcp.preferencewindow.builder.PreferenceWindowModel) PreferenceTabDescriptor(aero.minova.rcp.preferencewindow.builder.PreferenceTabDescriptor) PreferenceDescriptor(aero.minova.rcp.preferencewindow.builder.PreferenceDescriptor) BackingStoreException(org.osgi.service.prefs.BackingStoreException) PreferenceSectionDescriptor(aero.minova.rcp.preferencewindow.builder.PreferenceSectionDescriptor) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) Shell(org.eclipse.swt.widgets.Shell) PWSeparator(org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWSeparator) PWTab(org.eclipse.nebula.widgets.opal.preferencewindow.PWTab) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 5 with TranslationService

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) DateTimeValueAccessor(aero.minova.rcp.rcp.accessor.DateTimeValueAccessor) FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Instant(java.time.Instant) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) FocusEvent(org.eclipse.swt.events.FocusEvent) TextAssistContentProvider(org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider) Value(aero.minova.rcp.model.Value) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Preferences(org.osgi.service.prefs.Preferences) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) FormAttachment(org.eclipse.swt.layout.FormAttachment) CssData(aero.minova.rcp.css.CssData)

Aggregations

ArrayList (java.util.ArrayList)8 ApplicationPreferences (aero.minova.rcp.preferences.ApplicationPreferences)7 Table (aero.minova.rcp.model.Table)6 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)6 Execute (org.eclipse.e4.core.di.annotations.Execute)6 Row (aero.minova.rcp.model.Row)5 Value (aero.minova.rcp.model.Value)5 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)5 CssData (aero.minova.rcp.css.CssData)4 Preferences (aero.minova.rcp.form.setup.xbs.Preferences)4 FormAttachment (org.eclipse.swt.layout.FormAttachment)4 FormData (org.eclipse.swt.layout.FormData)4 Label (org.eclipse.swt.widgets.Label)4 MField (aero.minova.rcp.model.form.MField)3 WFCIndexPart (aero.minova.rcp.rcp.parts.WFCIndexPart)3 MPerspective (org.eclipse.e4.ui.model.application.ui.advanced.MPerspective)3 Constants (aero.minova.rcp.constants.Constants)2 Entry (aero.minova.rcp.form.setup.xbs.Map.Entry)2 Node (aero.minova.rcp.form.setup.xbs.Node)2 Instant (java.time.Instant)2