Search in sources :

Example 1 with PlainMessageDialog

use of org.eclipse.jface.dialogs.PlainMessageDialog 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 2 with PlainMessageDialog

use of org.eclipse.jface.dialogs.PlainMessageDialog in project aero.minova.rcp by minova-afis.

the class TextButtonForCurrentWorkspace method build.

/**
 * @see org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
 */
@Override
public Control build(final Composite parent) {
    final Label label = new Label(parent, SWT.NONE);
    label.setText(getLabel());
    label.setToolTipText(getTooltip());
    addControl(label);
    final GridData labelGridData = new GridData(SWT.END, SWT.CENTER, false, false);
    labelGridData.horizontalIndent = getIndent();
    label.setLayoutData(labelGridData);
    Composite cmp = new Composite(parent, SWT.NONE);
    cmp.setLayout(new GridLayout(3, false));
    addControl(cmp);
    final Text text = new Text(cmp, SWT.BORDER | SWT.READ_ONLY);
    text.setToolTipText(getTooltip());
    addControl(text);
    final GridData textGridData = new GridData(SWT.BEGINNING, SWT.CENTER, true, false);
    textGridData.widthHint = 250;
    text.setLayoutData(textGridData);
    if (dataService != null) {
        text.setText(dataService.getStoragePath().toAbsolutePath().toString());
    } else {
        text.setText(translationService.translate("Not found", null));
    }
    final Button openButton = new Button(cmp, SWT.PUSH);
    GridData buttonGridData = new GridData(SWT.FILL, SWT.CENTER, false, false);
    openButton.setText(translationService.translate("@Action.Open", null));
    openButton.setLayoutData(buttonGridData);
    openButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                Desktop.getDesktop().open(dataService.getStoragePath().toAbsolutePath().toFile());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });
    final Button deleteButton = new Button(cmp, SWT.PUSH);
    buttonGridData = new GridData(SWT.FILL, SWT.CENTER, false, false);
    deleteButton.setText(translationService.translate("@Action.Delete", null));
    deleteButton.setLayoutData(buttonGridData);
    deleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            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("@msg.WFCDeleteWorkspaceRestart", null)).build();
            if (confirmRestart.open() == 0) {
                context.set(IWorkbench.PERSIST_STATE, false);
                try {
                    FileUtils.deleteDirectory(dataService.getStoragePath().toAbsolutePath().toFile());
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                workbench.restart();
            }
        }
    });
    return deleteButton;
}
Also used : PlainMessageDialog(org.eclipse.jface.dialogs.PlainMessageDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException)

Aggregations

PlainMessageDialog (org.eclipse.jface.dialogs.PlainMessageDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 PreferenceDescriptor (aero.minova.rcp.preferencewindow.builder.PreferenceDescriptor)1 PreferenceSectionDescriptor (aero.minova.rcp.preferencewindow.builder.PreferenceSectionDescriptor)1 PreferenceTabDescriptor (aero.minova.rcp.preferencewindow.builder.PreferenceTabDescriptor)1 PreferenceWindowModel (aero.minova.rcp.preferencewindow.builder.PreferenceWindowModel)1 IOException (java.io.IOException)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 MHandler (org.eclipse.e4.ui.model.application.commands.MHandler)1 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)1 PWTab (org.eclipse.nebula.widgets.opal.preferencewindow.PWTab)1 PreferenceWindow (org.eclipse.nebula.widgets.opal.preferencewindow.PreferenceWindow)1 PWSeparator (org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWSeparator)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1