Skip to content

Commit

Permalink
Gets rid of the blind usage of WorkbenchHelper.getSheet();
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Sep 17, 2021
1 parent dc2db7b commit 3875937
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 60 deletions.
@@ -1,14 +1,13 @@
/*********************************************************************************************
/*******************************************************************************************************
*
* 'SyntaxErrorsView.java, in plugin ummisco.gama.ui.modeling, is part of the source code of the GAMA modeling and
* simulation platform. (v. 1.8.1)
* SyntaxErrorsView.java, in ummisco.gama.ui.modeling, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
**********************************************************************************************/
********************************************************************************************************/
package ummisco.gama.ui.views;

import java.lang.reflect.InvocationTargetException;
Expand All @@ -34,19 +33,30 @@
import msi.gama.common.preferences.IPreferenceChangeListener.IPreferenceAfterChangeListener;
import ummisco.gama.ui.commands.TestsRunner;
import ummisco.gama.ui.resources.IGamaColors;
import ummisco.gama.ui.utils.WorkbenchHelper;
import ummisco.gama.ui.views.toolbar.GamaToolbar2;
import ummisco.gama.ui.views.toolbar.GamaToolbarFactory;
import ummisco.gama.ui.views.toolbar.IToolbarDecoratedView;

/**
* The Class SyntaxErrorsView.
*/
public class SyntaxErrorsView extends MarkerSupportView implements IToolbarDecoratedView {

/** The parent. */
protected Composite parent;

/** The toolbar. */
protected GamaToolbar2 toolbar;

/** The info action. */
ToolItem warningAction, infoAction;

/** The listener. */
final BuildPreferenceChangeListener listener;

/**
* Instantiates a new syntax errors view.
*/
public SyntaxErrorsView() {
super("msi.gama.lang.gaml.ui.error.generator");
listener = new BuildPreferenceChangeListener(this);
Expand All @@ -67,10 +77,25 @@ public void dispose() {
GamaPreferences.Modeling.INFO_ENABLED.removeChangeListener(listener);
}

/**
* The listener interface for receiving buildPreferenceChange events. The class that is interested in processing a
* buildPreferenceChange event implements this interface, and the object created with that class is registered with
* a component using the component's <code>addBuildPreferenceChangeListener<code> method. When the
* buildPreferenceChange event occurs, that object's appropriate method is invoked.
*
* @see BuildPreferenceChangeEvent
*/
public static class BuildPreferenceChangeListener implements IPreferenceAfterChangeListener<Boolean> {

/** The view. */
SyntaxErrorsView view;

/**
* Instantiates a new builds the preference change listener.
*
* @param v
* the v
*/
BuildPreferenceChangeListener(final SyntaxErrorsView v) {
view = v;
}
Expand All @@ -85,13 +110,12 @@ public void afterValueChange(final Boolean newValue) {
}
}

/**
* Check actions.
*/
void checkActions() {
if (warningAction != null) {
warningAction.setSelection(GamaPreferences.Modeling.WARNINGS_ENABLED.getValue());
}
if (infoAction != null) {
infoAction.setSelection(GamaPreferences.Modeling.INFO_ENABLED.getValue());
}
if (warningAction != null) { warningAction.setSelection(GamaPreferences.Modeling.WARNINGS_ENABLED.getValue()); }
if (infoAction != null) { infoAction.setSelection(GamaPreferences.Modeling.INFO_ENABLED.getValue()); }
}

@Override
Expand All @@ -116,21 +140,28 @@ public void createToolItems(final GamaToolbar2 tb) {
infoAction.setSelection(GamaPreferences.Modeling.INFO_ENABLED.getValue());

tb.sep(GamaToolbarFactory.TOOLBAR_SEP, SWT.RIGHT);
tb.button("build.all2", "", "Clean and validate all projects", e -> {
build();
}, SWT.RIGHT);
tb.button("build.all2", "", "Clean and validate all projects", e -> { build(); }, SWT.RIGHT);

tb.button("test.run2", "", "Run all tests", e -> TestsRunner.start(), SWT.RIGHT);

}

/**
* Open filter dialog.
*/
void openFilterDialog() {
final IEvaluationContext ec = new EvaluationContext(null, this);
ec.addVariable(ISources.ACTIVE_PART_NAME, this);
final ExecutionEvent ev = new ExecutionEvent(null, new HashMap<>(), this, ec);
new ConfigureContentsDialogHandler().execute(ev);
}

/**
* Do build.
*
* @param monitor
* the monitor
*/
static private void doBuild(final IProgressMonitor monitor) {
try {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor);
Expand All @@ -149,14 +180,17 @@ static private void doBuild(final IProgressMonitor monitor) {
}
}

/**
* Builds the.
*/
static void build() {

final ProgressMonitorDialog dialog = new ProgressMonitorDialog(WorkbenchHelper.getShell());
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
dialog.setBlockOnOpen(false);
dialog.setCancelable(false);
dialog.setOpenOnRun(true);
try {
dialog.run(true, false, monitor -> doBuild(monitor));
dialog.run(true, false, SyntaxErrorsView::doBuild);
} catch (InvocationTargetException | InterruptedException e1) {
e1.printStackTrace();
}
Expand Down
@@ -1,14 +1,13 @@
/*********************************************************************************************
/*******************************************************************************************************
*
* 'FileOpener.java, in plugin ummisco.gama.ui.modeling, is part of the source code of the GAMA modeling and simulation
* platform. (v. 1.8.1)
* FileOpener.java, in ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
*
**********************************************************************************************/
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package ummisco.gama.ui.commands;

import org.eclipse.core.filesystem.EFS;
Expand All @@ -34,63 +33,77 @@
*/
public class FileOpener {

/** The Constant PAGE. */
static final IWorkbenchPage PAGE = WorkbenchHelper.getPage();

/**
* Open file.
*
* @param uri the uri
* @return the i editor part
*/
public static IEditorPart openFile(final URI uri) {
if (uri == null) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found", "Trying to open a null file");
MessageDialog.openWarning(null, "No file found", "Trying to open a null file");
return null;
}
try {
if (uri.isPlatformResource()) { return FileOpener.openFileInWorkspace(uri); }
if (uri.isFile()) { return FileOpener.openFileInFileSystem(uri); }
if (uri.isPlatformResource()) return FileOpener.openFileInWorkspace(uri);
if (uri.isFile()) return FileOpener.openFileInFileSystem(uri);
} catch (final PartInitException e) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
MessageDialog.openWarning(null, "No file found",
"The file'" + uri.toString() + "' does not exist on disk.");
}
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
"The file'" + uri.toString() + "' cannot be found.");
MessageDialog.openWarning(null, "No file found", "The file'" + uri.toString() + "' cannot be found.");
return null;
}

/**
* Open file in workspace.
*
* @param uri the uri
* @return the i editor part
* @throws PartInitException the part init exception
*/
public static IEditorPart openFileInWorkspace(final URI uri) throws PartInitException {
final IFile file = FileUtils.getWorkspaceFile(uri);
if (file == null) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
"The file'" + uri.toString() + "' cannot be found.");
MessageDialog.openWarning(null, "No file found", "The file'" + uri.toString() + "' cannot be found.");
return null;
}
if (file.isLinked()) {
if (!NavigatorRoot.getInstance().getManager().validateLocation(file)) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found", "The file'"
+ file.getRawLocation() + "' referenced by '" + file.getName() + "' cannot be found.");
return null;
}
if (file.isLinked() && !NavigatorRoot.getInstance().getManager().validateLocation(file)) {
MessageDialog.openWarning(null, "No file found",
"The file'" + file.getRawLocation() + "' referenced by '" + file.getName() + "' cannot be found.");
return null;
}
return IDE.openEditor(PAGE, file);
}

/**
* Open file in file system.
*
* @param uri the uri
* @return the i editor part
* @throws PartInitException the part init exception
*/
public static IEditorPart openFileInFileSystem(final URI uri) throws PartInitException {
if (uri == null) { return null; }
if (uri == null) return null;
IFileStore fileStore;
try {
fileStore = EFS.getLocalFileSystem().getStore(Path.fromOSString(uri.toFileString()));
} catch (final Exception e1) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
"The file'" + uri.toString() + "' cannot be found.");
MessageDialog.openWarning(null, "No file found", "The file'" + uri.toString() + "' cannot be found.");
return null;
}
IFileInfo info;
try {
info = fileStore.fetchInfo();
} catch (final Exception e) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
"The file'" + uri.toString() + "' cannot be found.");
MessageDialog.openWarning(null, "No file found", "The file'" + uri.toString() + "' cannot be found.");
return null;
}
if (!info.exists()) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
"The file'" + uri.toString() + "' cannot be found.");
MessageDialog.openWarning(null, "No file found", "The file'" + uri.toString() + "' cannot be found.");
}
return IDE.openInternalEditorOnFileStore(PAGE, fileStore);
}
Expand Down
50 changes: 38 additions & 12 deletions ummisco.gama.ui.shared/src/ummisco/gama/ui/dialogs/Messages.java
@@ -1,36 +1,62 @@
/*********************************************************************************************
/*******************************************************************************************************
*
* 'Messages.java, in plugin ummisco.gama.ui.shared, is part of the source code of the GAMA modeling and simulation
* platform. (v. 1.8.1)
* Messages.java, in ummisco.gama.ui.shared, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
*
**********************************************************************************************/
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package ummisco.gama.ui.dialogs;

import org.eclipse.jface.dialogs.MessageDialog;

import ummisco.gama.ui.utils.WorkbenchHelper;

/**
* The Class Messages.
*/
public class Messages {

/**
* Error.
*
* @param error the error
*/
public static void error(final String error) {
WorkbenchHelper.run(() -> MessageDialog.openError(WorkbenchHelper.getShell(), "Error", error));
WorkbenchHelper.run(() -> MessageDialog.openError(null, "Error", error));
}

/**
* Tell.
*
* @param error the error
*/
public static void tell(final String error) {
WorkbenchHelper.run(() -> MessageDialog.openInformation(WorkbenchHelper.getShell(), "Message", error));
WorkbenchHelper.run(() -> MessageDialog.openInformation(null, "Message", error));
}

/**
* Question.
*
* @param title the title
* @param message the message
* @return true, if successful
*/
public static boolean question(final String title, final String message) {
return MessageDialog.openQuestion(WorkbenchHelper.getShell(), title, message);
return MessageDialog.openQuestion(null, title, message);
}

/**
* Confirm.
*
* @param title the title
* @param message the message
* @return true, if successful
*/
public static boolean confirm(final String title, final String message) {
return MessageDialog.openConfirm(WorkbenchHelper.getShell(), title, message);
return MessageDialog.openConfirm(null, title, message);
}

}

0 comments on commit 3875937

Please sign in to comment.