Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
package de.tutorials.jdt.extension.popup.actions;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
public class NewAction implements IObjectActionDelegate {
StructuredSelection structuredSelection;
/**
* Constructor for Action1.
*/
public NewAction() {
super();
}
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
if (null != structuredSelection) {
Object element = structuredSelection.getFirstElement();
if (null != element && element instanceof ICompilationUnit) {
ICompilationUnit compilationUnit = (ICompilationUnit) element;
try {
IType[] types = compilationUnit.getTypes();
IMethod[] methods = types[0].getMethods();
StringBuilder stringBuilder = new StringBuilder("Type: ");
stringBuilder.append(types[0].getFullyQualifiedName());
stringBuilder.append("has Methods: ");
for (IMethod method : methods) {
stringBuilder.append("\n" + method.getElementName());
}
Shell shell = new Shell();
MessageDialog.openInformation(shell, "Extension Plug-in", stringBuilder.toString());
} catch (JavaModelException e) {
e.printStackTrace();
}
}
}
}
/**
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
if (selection instanceof StructuredSelection) {
structuredSelection = (StructuredSelection) selection;
}
}
}