本文整理汇总了Java中org.eclipse.jface.viewers.TreeSelection.getFirstElement方法的典型用法代码示例。如果您正苦于以下问题:Java TreeSelection.getFirstElement方法的具体用法?Java TreeSelection.getFirstElement怎么用?Java TreeSelection.getFirstElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.viewers.TreeSelection
的用法示例。
在下文中一共展示了TreeSelection.getFirstElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
TreeSelection selection = (TreeSelection) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IAdaptable)
{
IFile file = (IFile)((IAdaptable)firstElement).getAdapter(IFile.class);
IPath path = file.getLocation();
try {
//TODO fix
SurveyGenerator.generateAll(path.toOSString(), path.toOSString());
MessageDialog.openInformation(shell, "Success", "Code was generated successfully");
} catch (Exception e) {
//MessageDialog.openError(shell, "Error", e.getMessage());
e.printStackTrace();
}
}
return null;
}
示例2: selectionChanged
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
public void selectionChanged(SelectionChangedEvent event) {
Object firstElement = null;
if (event.getSelection() instanceof TreeSelection) {
TreeSelection treeSelection = (TreeSelection) event
.getSelection();
firstElement = treeSelection.getFirstElement();
}
if (firstElement instanceof ISourceImage) {
Image image = ((ISourceImage) firstElement).getImage();
imagesBrowseDialog
.setSelectedResource((ISourceImage) firstElement);
imagesBrowseDialog.showImage(image);
} else {
imagesBrowseDialog.setSelectedResource(null);
imagesBrowseDialog.showImage(null);
}
}
示例3: fillContextMenu
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
/**
* fillContextMenu
*
* @param manager
*/
private void fillContextMenu(IMenuManager manager)
{
ISelection selection = treeViewer.getSelection();
if (selection instanceof TreeSelection)
{
TreeSelection treeSelection = (TreeSelection) selection;
Object item = treeSelection.getFirstElement();
if (item != null)
{
IAction[] actions = actionProvider.getActions(this, item);
if (actions != null)
{
for (IAction action : actions)
{
manager.add(action);
}
}
}
}
}
示例4: getModelHandle
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
private ModelHandle getModelHandle() {
ModelHandle handle = null;
ISelection selection = viewer.getSelection();
if (selection instanceof TreeSelection) {
TreeSelection treeSelection = (TreeSelection) selection;
if (treeSelection.size() == 1) {
Object selObj = treeSelection.getFirstElement();
if(selObj instanceof ModelCodeTreeNode) {
ModelCodeTreeNode modelCodeNode = (ModelCodeTreeNode)selObj;
try {
handle = modelCodeNode.getActiveModelHandle();
} catch (EntryNotFoundException e) {
// ignore and just interpret as non-drag-able...
}
}
}
}
return handle;
}
示例5: getFirstSelectedElement
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
/**
* @param selection
* @return first element of the selection
*/
public static Object getFirstSelectedElement(ISelection selection) {
if (selection instanceof TreeSelection) {
TreeSelection treeSelection = (TreeSelection) selection;
return treeSelection.getFirstElement();
} else if (selection instanceof StructuredSelection) {
StructuredSelection structuredSelection = (StructuredSelection) selection;
return structuredSelection.getFirstElement();
} else if (selection instanceof IFileEditorInput) {
IFileEditorInput editorInput = (FileEditorInput) selection;
return editorInput.getFile();
} else if (selection instanceof TextSelection) {
return null;
} else {
throw new RuntimeException(
Messages.GeneratorUtils_SelectionNotSupported);
}
}
示例6: open
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
/***********************************************************************
* Open event on double click
**********************************************************************/
@Override
public void open(OpenEvent event)
{
TreeSelection sel = (TreeSelection) event.getSelection();
try
{
ProcedureNode item = (ProcedureNode) sel.getFirstElement();
// Open procedures only, ignore categories
String category = item.getProcID();
if (category == null || category.equals("") || category.equals("CATEGORY"))
{
return;
}
CommandHelper.execute(OpenProcedure.ID);
}
catch (Exception e)
{
return;
}
}
示例7: selectionChanged
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
/***********************************************************************
* Selection changed on the tree
**********************************************************************/
@Override
public void selectionChanged(SelectionChangedEvent event)
{
TreeSelection sel = (TreeSelection) event.getSelection();
IRuntimeSettings runtime = (IRuntimeSettings) ServiceManager.get(IRuntimeSettings.class);
try
{
ProcedureNode item = (ProcedureNode) sel.getFirstElement();
runtime.setRuntimeProperty(RuntimeProperty.ID_NAVIGATION_VIEW_SELECTION, item.getProcID());
}
catch (Exception ex)
{
runtime.setRuntimeProperty(RuntimeProperty.ID_NAVIGATION_VIEW_SELECTION, null);
}
}
示例8: doubleClick
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
public void doubleClick(TreeViewer treeViewer) {
TreeSelection ts = (TreeSelection) treeViewer.getSelection();
Object el = ts.getFirstElement();
if (el instanceof MFolder) {
if (treeViewer.getExpandedState(el))
treeViewer.collapseToLevel(el, 1);
else {
if (refreshAction.isEnabled())
refreshAction.run();
treeViewer.expandToLevel(el, 1);
}
}
if (el instanceof MInputControl && editAction.isEnabled()) {
editAction.run();
return;
}
if (editServerAction.isEnabled())
editServerAction.run();
// if (runReportUnitAction.isEnabled())
// runReportUnitAction.run();
else if (openInEditorAction.isEnabled())
openInEditorAction.run();
else if (runReportUnitAction.isEnabled())
runReportUnitAction.run();
}
示例9: fillContextMenu
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
/**
* fillContextMenu
*
* @param manager
*/
private void fillContextMenu(IMenuManager manager)
{
ISelection selection = treeViewer.getSelection();
if (selection instanceof TreeSelection)
{
TreeSelection treeSelection = (TreeSelection) selection;
Object item = treeSelection.getFirstElement();
if (item instanceof BaseNode)
{
BaseNode<?> node = (BaseNode<?>) item;
Action[] actions = node.getActions();
if (actions != null)
{
for (Action action : actions)
{
manager.add(action);
}
}
}
}
}
示例10: doFindResource
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
public static void doFindResource(ServerProvider sp, TreeViewer treeViewer) {
TreeSelection ts = (TreeSelection) treeViewer.getSelection();
Object el = ts.getFirstElement();
MServerProfile msp = null;
if (el instanceof MServerProfile)
msp = (MServerProfile) el;
else if (el instanceof MResource) {
INode n = ((MResource) el).getRoot();
if (n != null && n instanceof MServerProfile)
msp = (MServerProfile) n;
}
if (msp != null) {
FindResourceWizard wizard = new FindResourceWizard(msp);
WizardDialog dialog = new FindWizardDialog(UIUtils.getShell(), wizard);
dialog.setHelpAvailable(false);
dialog.create();
if (dialog.open() == Dialog.OK) {
ResourceDescriptor rd = wizard.getValue();
if (rd != null)
selectResource(sp, msp, rd, treeViewer);
}
}
}
示例11: run
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
@Override
public void run() {
IConnection conn = null;
TreeSelection selection = (TreeSelection) treeViewer.getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement != null) {
if (firstElement instanceof MServerProfile)
conn = ((MServerProfile) firstElement).getWsClient();
else if (firstElement instanceof MResource)
conn = ((MResource) firstElement).getWsClient();
}
if (conn != null) {
ImportMetadataWizard wizard = new ImportMetadataWizard(conn);
WizardDialog dialog = new WizardDialog(UIUtils.getShell(), wizard);
dialog.create();
if (dialog.open() == Dialog.OK) {
}
}
}
示例12: setupNewFileName
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
public void setupNewFileName() {
String filename = NEW_FILENAME;
if (selection != null) {
if (selection instanceof TreeSelection) {
TreeSelection s = (TreeSelection) selection;
if (s.getFirstElement() instanceof IFile) {
IFile file = (IFile) s.getFirstElement();
String f = file.getProjectRelativePath().removeLastSegments(1).toOSString() + "/" + filename;//$NON-NLS-1$
int i = 1;
while (file.getProject().getFile(f).exists()) {
filename = NEW_NAME + i + NEW_EXT;
f = file.getProjectRelativePath().removeLastSegments(1).toOSString() + "/" + filename;//$NON-NLS-1$
i++;
}
}
}
step1.setFileName(filename);
}
}
示例13: setupNewFileName
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
public void setupNewFileName() {
String filename = NEW_DATAADAPTER_XML;
if (selection != null) {
if (selection instanceof TreeSelection) {
TreeSelection s = (TreeSelection) selection;
if (s.getFirstElement() instanceof IFile) {
IFile file = (IFile) s.getFirstElement();
String f = file.getProjectRelativePath().removeLastSegments(1).toOSString() + "/" + filename; //$NON-NLS-1$
int i = 1;
while (file.getProject().getFile(f).exists()) {
filename = "NEW_DATAADAPTER" + i + ".xml"; //$NON-NLS-1$ //$NON-NLS-2$
f = file.getProjectRelativePath().removeLastSegments(1).toOSString() + "/" + filename; //$NON-NLS-1$
i++;
}
}
}
step1.setFileName(filename);
}
}
示例14: setupNewFileName
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
public void setupNewFileName() {
String filename = NEW_STYLE_JRTX;
if (selection != null) {
if (selection instanceof TreeSelection) {
TreeSelection s = (TreeSelection) selection;
if (s.getFirstElement() instanceof IFile) {
IFile file = (IFile) s.getFirstElement();
String f = file.getProjectRelativePath().removeLastSegments(1).toOSString() + "/" + filename;//$NON-NLS-1$
int i = 1;
while (file.getProject().getFile(f).exists()) {
filename = NEW_STYLE_NAME + i + NEW_STYLE_EXT;
f = file.getProjectRelativePath().removeLastSegments(1).toOSString() + "/" + filename;//$NON-NLS-1$
i++;
}
}
}
step1.setFileName(filename);
}
}
示例15: doubleClick
import org.eclipse.jface.viewers.TreeSelection; //导入方法依赖的package包/类
/**
* The callback function for the double click listener. Finds what was
* clicked on, if its a rule show it in the editor (or focus on the already
* open editor).
*/
/* Override */
public void doubleClick( DoubleClickEvent event )
{
if( event.getSelection() instanceof TreeSelection ) {
TreeSelection selected = (TreeSelection) event.getSelection();
if( selected.getFirstElement() != null ) {
switch( ((ModelElement) selected.getFirstElement()).getModelType() ) {
case RULE:
TrafficScriptEditor.openEditorForRule( (Rule) selected.getFirstElement() );
break;
}
}
}
}