Skip to content

Commit

Permalink
code cleanup and renaming
Browse files Browse the repository at this point in the history
implement suggested changes (rename classes, move to method to util class)

Signed-off-by: Christoph Rueger <[email protected]>
  • Loading branch information
chrisrueger committed Oct 31, 2023
1 parent 2591b3a commit 81cb4ee
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,81 +1,40 @@
package bndtools.editor.common;

import org.bndtools.core.ui.icons.Icons;
import static bndtools.utils.EditorUtils.createButton;
import static bndtools.utils.EditorUtils.createButtonWithText;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.program.Program;

/**
* Helper containing help buttons for different parts / views which link to the
* user manual.
*/
public final class Buttons {
public final class HelpButtons {

public static final Action HELP_BTN_REPOSITORIES = createHelpButton(
public static final Action HELP_BTN_REPOSITORIES = createButton(
"https://bndtools.org/manual/repositories-view.html",
"The Repositories View provides a user-friendly interface to inspect and manage the bundle repositories that are available to your Bndtools projects. Click to open manual in the browser.");

public static final Action HELP_BTN_BNDTOOLS_EXPLORER = createHelpButton(
public static final Action HELP_BTN_BNDTOOLS_EXPLORER = createButton(
"https://bndtools.org/manual/packageexplorer.html",
"The explorer provides an overview of the projects and their contents and allows advanced filtering. Click to open manual in the browser.");

public static final Action HELP_BTN_RESOLUTION_VIEW = createHelpButton(
public static final Action HELP_BTN_RESOLUTION_VIEW = createButton(
"https://bndtools.org/manual/resolution-view.html",
"The Resolution view shows the requirements and capabilities of one or multiple selected items, be they bnd.bnd files, JAR files, or entries in the Repositories view. This is useful for understanding dependencies as it provides information about what requirements are matched with what capabilities from the included resources. Click to open manual in the browser.");

public static final Action HELP_BTN_BND_EDITOR = createHelpButton(
public static final Action HELP_BTN_BND_EDITOR = createButton(
"https://bndtools.org/manual/bndeditor.html",
"This editor allows to edit bnd.bnd files, which define OSGi bundle metadata and build instructions for Java projects, encompassing sections for builtpath, imports, exports, bundle headers, and instructions to control the generation of the resulting OSGi bundle. Click to open manual in the browser.");

public static final Action HELP_BTN_BND_EDITOR_WORKSPACE = createHelpButton(
public static final Action HELP_BTN_BND_EDITOR_WORKSPACE = createButton(
"https://bndtools.org/manual/bndeditor.html",
"This editor allows to edit global .bnd files such as the main cnf/build.bnd, which serves as the central configuration hub for the entire bndtools workspace, allowing users to define and manage global build settings, plugins, repository references, and other overarching workspace properties. Click to open manual in the browser.");

public static final ActionContributionItem HELP_BTN_BND_EDITOR_RUN = createHelpButtonWithText(
public static final ActionContributionItem HELP_BTN_BND_EDITOR_RUN = createButtonWithText(
"https://bndtools.org/manual/bndeditor.html#run", "Help",
"The bnd editor for .bndrun files facilitates dependency management, automated resolution of required bundles, configuration of JVM and framework properties, direct launching of OSGi instances for testing, and the export of run configurations as executable JARs. Click to open manual in the browser.");

/**
* Creates a help button with icon and tooltip.
*
* @param url
* @param tooltipText
* @return
*/
private static Action createHelpButton(String url, String tooltipText) {
Action btn = new Action("Help", IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
Program.launch(url);
}
};
btn.setEnabled(true);
btn.setToolTipText(tooltipText);
btn.setImageDescriptor(Icons.desc("help"));

return btn;
}

/**
* Creates a helpbutton with icon, text and tooltip.
*
* @param url
* @param buttonText
* @param tooltipText
* @return
*/
private static ActionContributionItem createHelpButtonWithText(String url, String buttonText, String tooltipText) {
Action btn = createHelpButton(url, tooltipText);
btn.setText(buttonText);

// the ActionContributionItem is required to display text below the icon
// of the button
ActionContributionItem helpContrib = new ActionContributionItem(btn);
helpContrib.setMode(ActionContributionItem.MODE_FORCE_TEXT);

return helpContrib;
}

private Buttons() {}
private HelpButtons() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import aQute.bnd.build.model.BndEditModel;
import aQute.bnd.build.model.clauses.ExportedPackage;
import aQute.bnd.build.model.clauses.ImportPattern;
import bndtools.editor.common.Buttons;
import bndtools.editor.common.HelpButtons;
import bndtools.editor.common.MDSashForm;
import bndtools.editor.contents.BundleCalculatedImportsPart;
import bndtools.editor.contents.GeneralInfoPart;
Expand Down Expand Up @@ -74,7 +74,7 @@ protected void createFormContent(IManagedForm managedForm) {
// buttons top of form
IToolBarManager toolbar = scrolledForm.getForm()
.getToolBarManager();
toolbar.add(Buttons.HELP_BTN_BND_EDITOR);
toolbar.add(HelpButtons.HELP_BTN_BND_EDITOR);
toolbar.update(true);

Form form = scrolledForm.getForm();
Expand Down
4 changes: 2 additions & 2 deletions bndtools.core/src/bndtools/editor/pages/ProjectRunPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import aQute.bnd.build.Workspace;
import aQute.bnd.build.model.BndEditModel;
import bndtools.central.Central;
import bndtools.editor.common.Buttons;
import bndtools.editor.common.HelpButtons;
import bndtools.editor.common.MDSashForm;
import bndtools.editor.project.AvailableBundlesPart;
import bndtools.editor.project.RepositorySelectionPart;
Expand Down Expand Up @@ -144,7 +144,7 @@ protected void createFormContent(IManagedForm managedForm) {
.add(exportContrib);

form.getToolBarManager()
.add(Buttons.HELP_BTN_BND_EDITOR_RUN);
.add(HelpButtons.HELP_BTN_BND_EDITOR_RUN);

form.getToolBarManager()
.update(true);
Expand Down
4 changes: 2 additions & 2 deletions bndtools.core/src/bndtools/editor/pages/WorkspacePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import aQute.bnd.build.model.BndEditModel;
import aQute.bnd.build.model.clauses.HeaderClause;
import bndtools.editor.common.Buttons;
import bndtools.editor.common.HelpButtons;
import bndtools.editor.workspace.PluginPathPart;
import bndtools.editor.workspace.PluginsPart;
import bndtools.editor.workspace.WorkspaceMainPart;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected void createFormContent(IManagedForm managedForm) {
// buttons top of form
IToolBarManager toolbar = form.getForm()
.getToolBarManager();
toolbar.add(Buttons.HELP_BTN_BND_EDITOR_WORKSPACE);
toolbar.add(HelpButtons.HELP_BTN_BND_EDITOR_WORKSPACE);
toolbar.update(false);

// Create controls
Expand Down
4 changes: 2 additions & 2 deletions bndtools.core/src/bndtools/explorer/BndtoolsExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import bndtools.Plugin;
import bndtools.central.Central;
import bndtools.central.sync.WorkspaceSynchronizer;
import bndtools.editor.common.Buttons;
import bndtools.editor.common.HelpButtons;
import bndtools.preferences.BndPreferences;
import bndtools.preferences.ui.BndPreferencePage;

Expand Down Expand Up @@ -239,7 +239,7 @@ public void linkActivated(HyperlinkEvent e) {
toolBarManager.add(pin);
toolBarManager.update(true);

toolBarManager.add(Buttons.HELP_BTN_BNDTOOLS_EXPLORER);
toolBarManager.add(HelpButtons.HELP_BTN_BNDTOOLS_EXPLORER);
toolBarManager.update(true);

return header;
Expand Down
46 changes: 46 additions & 0 deletions bndtools.core/src/bndtools/utils/EditorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

import java.lang.reflect.InvocationTargetException;

import org.bndtools.core.ui.icons.Icons;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.program.Program;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.forms.IFormPart;
Expand Down Expand Up @@ -36,4 +41,45 @@ public static final IFormPart findPartByClass(IManagedForm form, Class<? extends
}
return null;
}

/**
* Creates a button with icon and tooltip.
*
* @param url
* @param tooltipText
* @return
*/
public static final Action createButton(String url, String tooltipText) {
Action btn = new Action("Help", IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
Program.launch(url);
}
};
btn.setEnabled(true);
btn.setToolTipText(tooltipText);
btn.setImageDescriptor(Icons.desc("help"));

return btn;
}

/**
* Creates a button with icon, text and tooltip.
*
* @param url
* @param buttonText
* @param tooltipText
* @return
*/
public static final ActionContributionItem createButtonWithText(String url, String buttonText, String tooltipText) {
Action btn = createButton(url, tooltipText);
btn.setText(buttonText);

// the ActionContributionItem is required to display text below the icon
// of the button
ActionContributionItem helpContrib = new ActionContributionItem(btn);
helpContrib.setMode(ActionContributionItem.MODE_FORCE_TEXT);

return helpContrib;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
import bndtools.central.RepositoriesViewRefresher;
import bndtools.central.RepositoryUtils;
import bndtools.dnd.gav.GAVIPageListener;
import bndtools.editor.common.Buttons;
import bndtools.editor.common.HelpButtons;
import bndtools.model.repo.RepositoryBundle;
import bndtools.model.repo.RepositoryBundleVersion;
import bndtools.model.repo.RepositoryEntry;
Expand Down Expand Up @@ -879,7 +879,7 @@ private void fillToolBar(IToolBarManager toolBar) {
toolBar.add(new Separator());
toolBar.add(offlineAction);
toolBar.add(new Separator());
toolBar.add(Buttons.HELP_BTN_REPOSITORIES);
toolBar.add(HelpButtons.HELP_BTN_REPOSITORIES);
toolBar.add(new Separator());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import aQute.lib.io.IO;
import aQute.lib.strings.Strings;
import bndtools.Plugin;
import bndtools.editor.common.Buttons;
import bndtools.editor.common.HelpButtons;
import bndtools.model.repo.RepositoryResourceElement;
import bndtools.model.resolution.CapReqMapContentProvider;
import bndtools.model.resolution.CapabilityLabelProvider;
Expand Down Expand Up @@ -349,7 +349,7 @@ public void runWithEvent(Event event) {

doEEActionMenu(toolBarManager);

toolBarManager.add(Buttons.HELP_BTN_RESOLUTION_VIEW);
toolBarManager.add(HelpButtons.HELP_BTN_RESOLUTION_VIEW);

}

Expand Down

0 comments on commit 81cb4ee

Please sign in to comment.