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

Add property page for automatic type export #1000

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
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
Expand Up @@ -12,8 +12,9 @@
# - externalized all translatable strings
###############################################################################

AutomaticTypeExport_Enable=Enable automatic type export at save action
AutomaticTypeExport_ExternalModulesDirectory=Path to external modules directory
ExportTemplate_ExportTemplate=ExportTemplate [{0}]

TemplateExportFilter_CANCEL_ALL_LABEL_STRING=Cancel All
TemplateExportFilter_ErrorDuringTemplateGeneration=Error during template generation
TemplateExportFilter_EXPORT_CANCELED=Export was canceled\!
Expand Down
17 changes: 17 additions & 0 deletions plugins/org.eclipse.fordiac.ide.export/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
class="org.eclipse.fordiac.ide.export.builder.ExportBuilder">
</run>
</builder>
</extension>
<extension
point="org.eclipse.ui.propertyPages">
<page
class="org.eclipse.fordiac.ide.export.properties.AutomaticTypeExportPropertyPage"
id="org.eclipse.fordiac.ide.export.settingspage"
name="Automatic Type Export Settings">
<enabledWhen>
<adapt
type="org.eclipse.core.resources.IProject">
<test
property="org.eclipse.core.resources.projectNature"
value="org.eclipse.fordiac.ide.systemmanagement.FordiacNature">
</test>
</adapt>
</enabledWhen>
</page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
@SuppressWarnings("squid:S3008") // tell sonar the java naming convention does not make sense for this class
public final class Messages extends NLS {

private static final String BUNDLE_NAME = "org.eclipse.fordiac.ide.export.messages"; //$NON-NLS-1$
private static final String BUNDLE_NAME = "plugin"; //$NON-NLS-1$

public static String AutomaticTypeExport_Enable;

public static String AutomaticTypeExport_ExternalModulesDirectory;

public static String ExportTemplate_ExportTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ private PreferenceConstants() {
/** The Constant for the Compare Editor Preference. */
public static final String P_COMPARE_EDITOR = "compareeditor"; //$NON-NLS-1$

/** The Constant for the Automatic Type Export Preferences. */
public static final String ENABLE_AUTOMATIC_TYPE_EXPORT = "ENABLE_AUTOMATIC_TYPE_EXPORT"; //$NON-NLS-1$
public static final String EXTERNAL_MODULES_PATH = "EXTERNAL_MODULES_PATH"; //$NON-NLS-1$

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
public void initializeDefaultPreferences() {
final IPreferenceStore store = PreferenceConstants.STORE;
store.setDefault(PreferenceConstants.P_COMPARE_EDITOR, "None"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.ENABLE_AUTOMATIC_TYPE_EXPORT, false);

// TODO add useful default suggestion for the path: note this should have
// project scope since it will be a folder within the project
store.setDefault(PreferenceConstants.EXTERNAL_MODULES_PATH, ""); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*******************************************************************************
* Copyright (c) 2025 Primetals Technologies Austria GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Mario Kastner
* - initial API and implementation and/or initial documentation
*******************************************************************************/

package org.eclipse.fordiac.ide.export.properties;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.fordiac.ide.export.Messages;
import org.eclipse.fordiac.ide.export.preferences.PreferenceConstants;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

public class AutomaticTypeExportPropertyPage extends PropertyPage {

private DirectoryFieldEditor directoryEditor;
private BooleanFieldEditor checkboxEditor;
private Composite directoryEditorContainer;

@Override
protected Control createContents(final Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(composite);
GridDataFactory.fillDefaults().applyTo(composite);
createEnableCheckbox(composite);
createDirectoryEditor(composite);
return composite;
}

private void createEnableCheckbox(final Composite parent) {
final Composite checkboxEditorContainer = new Composite(parent, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(checkboxEditorContainer);

this.checkboxEditor = new BooleanFieldEditor(PreferenceConstants.ENABLE_AUTOMATIC_TYPE_EXPORT,
Messages.AutomaticTypeExport_Enable, checkboxEditorContainer);

checkboxEditor.setPreferenceStore(getPreferenceStore());
checkboxEditor.load();

if (checkboxEditor.getDescriptionControl(checkboxEditorContainer) instanceof final Button button) {
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
directoryEditor.setEnabled(checkboxEditor.getBooleanValue(), directoryEditorContainer);
super.widgetSelected(e);
}
});
}
}

@Override
protected void performDefaults() {
directoryEditor.loadDefault();
checkboxEditor.loadDefault();
directoryEditor.setEnabled(false, directoryEditorContainer);
super.performDefaults();
}

private void createDirectoryEditor(final Composite parent) {
// default directory for external module directory
directoryEditorContainer = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().applyTo(directoryEditorContainer);
this.directoryEditor = new DirectoryFieldEditor(PreferenceConstants.EXTERNAL_MODULES_PATH,
Messages.AutomaticTypeExport_ExternalModulesDirectory, directoryEditorContainer);
this.directoryEditor.setPreferenceStore(getPreferenceStore());
directoryEditor.load();
directoryEditor.setEnabled(getPreferenceStore().getBoolean(PreferenceConstants.ENABLE_AUTOMATIC_TYPE_EXPORT),
directoryEditorContainer);
}

@Override
protected IPreferenceStore doGetPreferenceStore() {
final ProjectScope projectScope = new ProjectScope(getProject());
return new ScopedPreferenceStore(projectScope, PreferenceConstants.EXPORT_PREFERENCES_ID);
}

@Override
public boolean performOk() {
if (directoryEditor.isValid()) {
directoryEditor.store();
} else {
// TODO show error message
}
checkboxEditor.store();
return super.performOk();
}

protected IProject getProject() {
return Adapters.adapt(getElement(), IProject.class);
}

}
Loading