List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:com.clustercontrol.notify.view.action.NotifyCopyAction.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // ???//from ww w .j av a2 s . c o m this.viewPart = HandlerUtil.getActivePart(event); NotifyListView view = null; try { view = (NotifyListView) this.viewPart.getAdapter(NotifyListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } NotifyListComposite composite = (NotifyListComposite) view.getListComposite(); WidgetTestUtil.setTestId(this, null, composite); StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection(); List<?> list = (List<?>) selection.getFirstElement(); String managerName = null; String notifyId = null; Integer notifyType = null; if (list != null && list.size() > 0) { managerName = (String) list.get(NotifyTableDefineNoCheckBox.MANAGER_NAME); notifyId = (String) list.get(NotifyTableDefineNoCheckBox.NOTIFY_ID); notifyType = (Integer) list.get(NotifyTableDefineNoCheckBox.NOTIFY_TYPE); } Table table = composite.getTableViewer().getTable(); WidgetTestUtil.setTestId(this, null, table); // ??????? if (notifyId != null && notifyType != null) { Shell shell = view.getListComposite().getShell(); if (openDialog(shell, managerName, notifyId, notifyType) == IDialogConstants.OK_ID) { int selectIndex = table.getSelectionIndex(); composite.update(); table.setSelection(selectIndex); } } else { MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.notify.8")); } return null; }
From source file:com.clustercontrol.notify.view.NotifyListView.java
License:Open Source License
public String getSelectedId() { StructuredSelection selection = (StructuredSelection) this.composite.getTableViewer().getSelection(); List<?> list = (List<?>) selection.getFirstElement(); String id = null;//from w w w . j a va2s. c o m if (list != null) { id = (String) list.get(GetNotifyTableDefineNoCheckBox.NOTIFY_ID); } return id; }
From source file:com.clustercontrol.notify.view.NotifyListView.java
License:Open Source License
@Override public String getSelectedOwnerRoleId() { StructuredSelection selection = (StructuredSelection) this.composite.getTableViewer().getSelection(); List<?> list = (List<?>) selection.getFirstElement(); String id = null;//from ww w. ja v a 2 s .co m if (list != null) { id = (String) list.get(GetNotifyTableDefineNoCheckBox.OWNER_ROLE); } return id; }
From source file:com.clustercontrol.repository.view.action.NodeCopyAction.java
License:Open Source License
/** * @see org.eclipse.core.commands.IHandler#execute *///from ww w.j a v a2s. co m @Override public Object execute(ExecutionEvent event) throws ExecutionException { this.viewPart = HandlerUtil.getActivePart(event); // ??????ID? NodeListView view = null; try { view = (NodeListView) this.viewPart.getAdapter(NodeListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); List<?> list = (List<?>) selection.getFirstElement(); String managerName = null; String facilityId = null; if (list == null) { return null; } managerName = (String) list.get(GetNodeListTableDefine.MANAGER_NAME); facilityId = (String) list.get(GetNodeListTableDefine.FACILITY_ID); if (facilityId != null) { // ? NodeCreateDialog dialog = new NodeCreateDialog(this.viewPart.getSite().getShell(), managerName, facilityId, false); // ??????????? if (dialog.open() == IDialogConstants.OK_ID) { view.update(); // ?????????? CommonTableViewer viewer = view.getComposite().getTableViewer(); viewer.setSelection(viewer.getSelection()); } } return null; }
From source file:com.clustercontrol.repository.view.action.NodeModifyAction.java
License:Open Source License
/** * @see org.eclipse.core.commands.IHandler#execute *///from w w w .j a v a 2 s . c o m @Override public Object execute(ExecutionEvent event) throws ExecutionException { this.viewPart = HandlerUtil.getActivePart(event); // ??????ID? NodeListView nodeListView = null; try { nodeListView = (NodeListView) this.viewPart.getAdapter(NodeListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (nodeListView == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = (StructuredSelection) nodeListView.getComposite().getTableViewer() .getSelection(); List<?> list = (List<?>) selection.getFirstElement(); if (list == null) { return null; } String managerName = (String) list.get(GetNodeListTableDefine.MANAGER_NAME); String facilityId = (String) list.get(GetNodeListTableDefine.FACILITY_ID); if (facilityId != null) { // ? NodeCreateDialog dialog = new NodeCreateDialog(this.viewPart.getSite().getShell(), managerName, facilityId, true); // ??????????? if (dialog.open() == IDialogConstants.OK_ID) { nodeListView.update(); // ?????????? CommonTableViewer viewer = nodeListView.getComposite().getTableViewer(); viewer.setSelection(viewer.getSelection()); } } return null; }
From source file:com.clustercontrol.repository.view.action.ProgramExecutionAction.java
License:Open Source License
/** * @see org.eclipse.core.commands.IHandler#execute *//*w w w .j a v a 2 s . c o m*/ @Override public Object execute(ExecutionEvent event) throws ExecutionException { this.viewPart = HandlerUtil.getActivePart(event); // ??????ID? NodeListView view = null; try { view = (NodeListView) this.viewPart.getAdapter(NodeListView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (view == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection(); List<?> list = (List<?>) selection.getFirstElement(); if (list == null) { return null; } String managerName = (String) list.get(GetNodeListTableDefine.MANAGER_NAME); String facilityId = (String) list.get(GetNodeListTableDefine.FACILITY_ID); if (facilityId == null) { return null; } // ? String execProg = ClusterControlPlugin.getDefault().getPreferenceStore() .getString(RepositoryPreferencePage.P_PROGRAM_EXECUTION); // ?? if (execProg.equals("")) { MessageDialog.openWarning(null, Messages.getString("warning"), Messages.getString("message.repository.49")); return null; } // ???????#????? if (execProg.indexOf("#") != -1) { try { // ???????????? RepositoryEndpointWrapper wrapper = RepositoryEndpointWrapper.getWrapper(managerName); execProg = wrapper.replaceNodeVariable(facilityId, execProg); } catch (InvalidRole_Exception e) { // ?????? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } catch (Exception e) { m_log.warn("run(), " + e.getMessage(), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); } } // ????? String[] args = null; try { String user = System.getProperty("user.name"); args = CommandCreator.createCommand(user, execProg, PlatformType.WINDOWS, false); } catch (HinemosUnknown e) { m_log.warn("run(), " + e.getMessage(), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); } StringBuffer message = new StringBuffer(); for (String arg : args) { message.append(arg + " "); } String messageStr = message.toString(); if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.repository.46", new String[] { messageStr }))) { // ? m_log.debug("program execution start : " + messageStr); try { new CommandExecutor(args).execute(); } catch (Exception e) { MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.repository.48") + ", " + HinemosMessage.replace(e.getMessage())); } } return null; }
From source file:com.clustercontrol.repository.view.NodeAttributeView.java
License:Open Source License
/** * ??????????/*from www . jav a 2 s . com*/ */ public void update() { IWorkbench workbench = ClusterControlPlugin.getDefault().getWorkbench(); IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); NodeListView view = null; if (page != null) { IViewPart viewPart = page.findView(NodeListView.ID); if (viewPart != null) { view = (NodeListView) viewPart.getAdapter(NodeListView.class); } } String managerName = null; String facilityId = null; if (view != null) { NodeListComposite composite = view.getComposite(); CommonTableViewer viewer = composite.getTableViewer(); StructuredSelection selection = (StructuredSelection) viewer.getSelection(); ArrayList<?> list = (ArrayList<?>) selection.getFirstElement(); if (list != null) { facilityId = (String) list.get(viewer.getTableColumnIndex(TableColumnInfo.FACILITY_ID)); managerName = (String) list.get(viewer.getTableColumnIndex(TableColumnInfo.MANAGER_NAME)); if (managerName == null || managerName.equals("")) { return; } String viewName = orgViewName + "(" + managerName + ")"; setPartName(viewName); } } else { m_log.info("update: view is null"); } this.composite.update(managerName, facilityId); }
From source file:com.clustercontrol.repository.view.NodeScopeView.java
License:Open Source License
/** * ??????????//from w w w . j av a 2 s. co m */ public void update() { IWorkbench workbench = ClusterControlPlugin.getDefault().getWorkbench(); IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); NodeListView view = null; if (page != null) { IViewPart viewPart = page.findView(NodeListView.ID); if (viewPart != null) { view = (NodeListView) viewPart.getAdapter(NodeListView.class); } } String managerName = null; String facilityId = null; String facilityName = null; if (view != null) { NodeListComposite composite = view.getComposite(); CommonTableViewer viewer = composite.getTableViewer(); StructuredSelection selection = (StructuredSelection) viewer.getSelection(); ArrayList<?> list = (ArrayList<?>) selection.getFirstElement(); if (list != null) { managerName = (String) list.get(viewer.getTableColumnIndex(TableColumnInfo.MANAGER_NAME)); facilityId = (String) list.get(viewer.getTableColumnIndex(TableColumnInfo.FACILITY_ID)); facilityName = (String) list.get(viewer.getTableColumnIndex(TableColumnInfo.FACILITY_NAME)); } } else { m_log.info("execute: view is null"); } this.composite.update(managerName, facilityId, facilityName); }
From source file:com.clustercontrol.view.ScopeListBaseView.java
License:Open Source License
/** * ????//from ww w. java 2 s . c o m * * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ @Override public void createPartControl(Composite parent) { m_log.trace("createPartControl"); super.createPartControl(parent); // GridLayout layout = new GridLayout(1, true); parent.setLayout(layout); layout.marginHeight = 0; layout.marginWidth = 0; // ??? this.treeSash = new SashForm(parent, SWT.HORIZONTAL); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = 1; this.treeSash.setLayoutData(gridData); // ? this.scopeTreeComposite = new FacilityTreeComposite(treeSash, SWT.NONE, null, this.scopeOnly, this.unregistered, this.internal, this.topicRefresh, false); // ??? this.baseComposite = new Composite(this.treeSash, SWT.NONE); WidgetTestUtil.setTestId(this, null, baseComposite); // ? this.pathLabel = new Label(this.baseComposite, SWT.NONE); WidgetTestUtil.setTestId(this, "path", pathLabel); this.pathLabel.setText(Messages.getString("scope") + " : "); // this.pathLabel.pack(); // ? this.listComposite = this.createListContents(this.baseComposite); // Sash? 30% ?70% treeSash.setWeights(new int[] { sashPer, 100 - sashPer }); // ?? this.scopeTreeComposite.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // ??(?????????) StructuredSelection selection = (StructuredSelection) event.getSelection(); FacilityTreeItem selectItem = (FacilityTreeItem) selection.getFirstElement(); if (selectItem != null) { // ? baseComposite.layout(true, true); // ?? doSelectTreeItem(selectItem); } } }); }
From source file:com.crispico.flower.mp.doc.DocumentationController.java
License:Open Source License
/** * This method must be called when the documentation controller must take it's information from a new element. * //from w w w. j av a 2s.c om * <p/> This controller will provide documentation content only if finds a single element in the selection, * that single element provides for a documentable element and labeled element which provide {@link IDocumentationProvider} * respectively an label provider. * * <p/> The behavior is to first remove the listeners on the old selection by calling {@link #clearSelection()}. * After it obtains the documentable element from {@link DocumentationUtils#getDocumentableElement(Object)} * and after it obtains the labeled element which is capable or obtaining the label provider. Listeners are added * if the selection is valid, and after {@link #processDocumentationContent()} is called for processing * and sending to the client the documentation content and {@link #processSelectionTitle()} is called for * processing and sending the label and the image to the client. In final {@link #processHasDocumentation()} * method will be called for telling the client that the pages must be switched. * @flowerModelElementId _kWZpgom4Ed-IjqfeDOxYSw */ public void setSelection(ISelection selection) { clearSelection(); // Take the first element of a structured selection and make sure that only 1 object was selected. Object selectedObject = null; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.size() == 1) { selectedObject = structuredSelection.getFirstElement(); } } // For the selected object we see if we can obtain a documentable element it means it provides for documentation Element documentableElement = DocumentationUtils.getDocumentableElement(selectedObject); if (documentableElement != null) { this.selectedElement = (Element) selectedObject; this.selectedDocumentableElement = documentableElement; // for the selected object we find the element which can give us a ItemProviderAdapter. this.selectedLabeledElement = (Element) findSelectedLabeledObject(selectedObject); // obtain an itemProviderAdapter to be used for text and image this.selectedLabelProvider = (ItemProviderAdapter) FlowerEditingDomain .getEditingDomainItemProviderFor(selectedLabeledElement); // an label item provider could not be found and we are sure that the selection id documentable so throw exception if (selectedLabelProvider == null) throw new IllegalStateException("Could not obtain a label item provider for selected element"); } if (selectedDocumentableElement != null) { //processDocumentationDetails(false, false); selectedDocumentableElement.eAdapters().add(this); selectedLabelProvider.addListener(this); } // we need to call the processing of the switching of the pages after then information has been set to the client // because otherwise, when changing from no doc to with doc, we would first the see the old documentation flickering // to the new documentation. processDocumentationDetails(true, true); }