List of usage examples for org.eclipse.jface.viewers TreeNode TreeNode
public TreeNode(final Object value)
TreeNode. From source file:com.apicloud.commons.model.Config.java
License:Open Source License
public TreeNode[] createTreeNode() { TreeNode components[] = new TreeNode[getFeatures().size()]; for (int i = 0; i < getFeatures().size(); i++) { TreeNode component = new TreeNode(getFeatures().get(i)); component.setChildren(getFeatures().get(i).createTreeNode(component)); components[i] = component;//from w w w .ja v a 2 s . c om } return components; }
From source file:com.apicloud.commons.model.Feature.java
License:Open Source License
public TreeNode[] createTreeNode(TreeNode parent) { int size = getParams().size(); TreeNode params[] = new TreeNode[size]; for (int i = 0; i < size; i++) { TreeNode param = new TreeNode(getParams().get(i)); param.setParent(parent);//from w w w. j av a 2s . co m params[i] = param; } return params; }
From source file:com.apicloud.navigator.dialogs.AddFeatureDialog.java
License:Open Source License
@Override protected void buttonPressed(int buttonId) { if (buttonId == IDialogConstants.OK_ID) { if (selectFeature == null) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, Messages.AddFeatureDialog_MESSAGE); return; }/*from w w w.j a va2 s . co m*/ for (Feature feature : config.getFeatures()) { if (feature.getName().equals(selectFeature.getName())) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, Messages.CreateFeatureDialog_FEATURE_NAME_DUP); return; } } if (text_urlScheme.isVisible() && text_urlScheme.getText().isEmpty()) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, lblParamkey.getText().trim() + Messages.AddFeatureDialog_MESSAGE_NULL); return; } if (text_apiKey.isVisible() && text_apiKey.getText().isEmpty()) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, lblParamvalue.getText().trim() + Messages.AddFeatureDialog_MESSAGE_NULL); return; } feature = new Feature(); feature.setName(selectFeature.getName()); if (text_urlScheme.isVisible()) { Param p = new Param(); p.setName("urlScheme"); if (feature.getName().equals("baiduMap")) { p.setName("android_api_key"); } p.setValue(text_urlScheme.getText()); feature.getParams().add(p); } if (text_apiKey.isVisible()) { Param p = new Param(); p.setName("apiKey"); if (feature.getName().equals("baiduMap")) { p.setName("ios_api_key"); } p.setValue(text_apiKey.getText()); feature.getParams().add(p); } config.addFeature(feature); TreeNode node = new TreeNode(feature); treeViewer.setInput(config.createTreeNode()); treeViewer.collapseAll(); StructuredSelection selection = new StructuredSelection(node); treeViewer.setSelection(selection, true); treeViewer.refresh(); editor.setDirty(true); editor.change(); } super.buttonPressed(buttonId); }
From source file:com.apicloud.navigator.dialogs.CreateFeatureDialog.java
License:Open Source License
@Override protected void buttonPressed(int buttonId) { setErrorMessage(null);/* w w w . j a v a 2s. c o m*/ if (buttonId == IDialogConstants.OK_ID) { if ("".equals(this.featureNameText.getText())) { //$NON-NLS-1$ setErrorMessage(Messages.CreateFeatureDialog_FEATURE_NMAE_NOT_NULL); return; } for (Feature feature : config.getFeatures()) { if (feature.getName().equals(this.featureNameText.getText())) { setErrorMessage(Messages.CreateFeatureDialog_FEATURE_NAME_DUP); return; } } feature = new Feature(); feature.setName(this.featureNameText.getText()); config.addFeature(feature); TreeNode node = new TreeNode(feature); treeViewer.setInput(config.createTreeNode()); treeViewer.collapseAll(); StructuredSelection selection = new StructuredSelection(node); treeViewer.setSelection(selection, true); treeViewer.refresh(); editor.setDirty(true); editor.change(); } super.buttonPressed(buttonId); }
From source file:com.apicloud.navigator.dialogs.CreateParamDialog.java
License:Open Source License
@Override protected void buttonPressed(int buttonId) { setErrorMessage(null);/*from w w w. j a v a 2 s. co m*/ if (buttonId == IDialogConstants.OK_ID) { if ("".equals(this.paramNameText.getText())) { //$NON-NLS-1$ setErrorMessage("param\u540D\u4E0D\u80FD\u4E3A\u7A7A"); //$NON-NLS-1$ return; } if ("".equals(this.paramValueText.getText())) { //$NON-NLS-1$ setErrorMessage("param\u503C\u4E0D\u80FD\u4E3A\u7A7A"); //$NON-NLS-1$ return; } StructuredSelection ss = (StructuredSelection) list.getSelection(); Feature feature = (Feature) ss.getFirstElement(); for (Param param : feature.getParams()) { if (param.getName().equals(this.paramNameText.getText())) { setErrorMessage(Messages.PARAMNAMEREPEAT); //$NON-NLS-1$ return; } } Param p = new Param(); p.setName(this.paramNameText.getText()); p.setValue(this.paramValueText.getText()); feature.addParams(p); TreeNode node = new TreeNode(p); node.setParent(new TreeNode(feature)); treeViewer.setInput(config.createTreeNode()); treeViewer.collapseAll(); StructuredSelection selection = new StructuredSelection(node); treeViewer.setSelection(selection, true); treeViewer.refresh(); editor.setDirty(true); editor.change(); } super.buttonPressed(buttonId); }
From source file:com.motorola.studio.android.codeutils.codegeneration.CreateSampleDatabaseActivityPage.java
License:Apache License
private TreeNode[] generateTreeViewerInput() { // Collection of TreeNodes HashSet<TreeNode> treeNodeColletion = new HashSet<TreeNode>(); // The selected project for which the activity will be created IProject project = getBuildBlock().getProject(); if (project != null) { // Get a collection of existing .db files inside the project Set<IFile> dbFilesSet = DatabaseUtils.getDbFilesFromProject(project); // Retrieve the database instances for (IFile dbFile : dbFilesSet) { try { // For each database retrieved, construct a TreeNode object containing itself and it's tables Database database = DatabaseUtils.getDatabase(project.getName(), dbFile.getName()); TreeNode treeNodeDatabase = new TreeNode(database); // Collection to store the table treeNodes from this database. Will be used later to set the children nodes of the database. HashSet<TreeNode> databaseChildren = new HashSet<TreeNode>(); // Construct another TreeTable object for each table and set the database tree node as the parent. // Tables don't have children for (Table table : DatabaseUtils.getTables(database)) { // Do not add ANDROID_METADATA table if (!table.getName().equalsIgnoreCase(ANDROID_METADATA_TABLE_NAME)) { TreeNode treeNodeTable = new TreeNode(table); treeNodeTable.setParent(treeNodeDatabase); // Add this node as a children of the database tree node. databaseChildren.add(treeNodeTable); }// w ww. j a v a 2 s. c o m } // Add the table nodes as the children of the database node treeNodeDatabase.setChildren(databaseChildren.toArray(new TreeNode[0])); // Add the database tree node to the resulting TreeNode collection that will serve as input treeNodeColletion.add(treeNodeDatabase); } catch (ConnectionProfileException e) { // Log error StudioLogger.error(DatabaseUtils.class, "A error ocurred while retrieving the connection profile.", e); } catch (IOException e) { // Log error StudioLogger.error(DatabaseUtils.class, "An I/O error ocurred.", e); } } } // Return a TreeNode array return treeNodeColletion.toArray(new TreeNode[0]); }
From source file:com.motorolamobility.studio.android.db.core.ui.wizards.createdb.CreateDatabaseWizardPage.java
License:Apache License
public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.FILL); composite.setLayout(new GridLayout(2, false)); GridData layoutData = new GridData(SWT.FILL, SWT.NONE, true, false); Composite nameComposite = new Composite(composite, SWT.FILL); nameComposite.setLayout(new GridLayout(2, false)); nameComposite.setLayoutData(layoutData); layoutData = new GridData(SWT.LEFT, SWT.NONE, false, false); Label dbNameLabel = new Label(nameComposite, SWT.NONE); dbNameLabel.setLayoutData(layoutData); dbNameLabel.setText(DbCoreNLS.CreateDatabaseWizardPage_DB_Name_Label); layoutData = new GridData(SWT.FILL, SWT.NONE, true, false); databaseName = new Text(nameComposite, SWT.BORDER | SWT.SINGLE); databaseName.setLayoutData(layoutData); databaseName.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validatePage();/*from w w w . j a v a 2s .c om*/ getContainer().updateButtons(); } }); Composite emptyComposite = new Composite(composite, SWT.RIGHT); emptyComposite.setLayout(new GridLayout(1, false)); emptyComposite.layout(); Group tableGroup = new Group(composite, SWT.FILL); GridLayout gridLayout = new GridLayout(2, false); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); tableGroup.setLayout(gridLayout); tableGroup.setLayoutData(gridData); tableGroup.setText(DbCoreNLS.CreateDatabaseWizardPage_Table_Group); viewer = new TreeViewer(tableGroup, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL); viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // Set content and label provider viewer.setLabelProvider(new TableLabelProvider()); viewer.setContentProvider(new TreeNodeContentProvider()); viewer.setInput(treeNodeArray); layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); viewer.getTree().setLayoutData(layoutData); viewer.addSelectionChangedListener(new TreeViewerListener()); Composite buttonBar = new Composite(tableGroup, SWT.NONE); layoutData = new GridData(SWT.RIGHT, SWT.TOP, false, true); buttonBar.setLayoutData(layoutData); buttonBar.setLayout(new FillLayout(SWT.VERTICAL)); addButton = new Button(buttonBar, SWT.PUSH); addButton.setText(DbCoreNLS.CreateDatabaseWizardPage_Add_Button); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean tableAdded = false; // loop used to validate the new table name. If it already exists // tell the user and open the table wizard again. while (!tableAdded) { CreateTableWizard createTableWizard = new CreateTableWizard(); WizardDialog dialog = new WizardDialog(getShell(), createTableWizard); dialog.open(); if (dialog.getReturnCode() == Dialog.OK) { TableModel newTable = createTableWizard.getTable(); if (newTable != null) { boolean tableNameAlreadyExists = false; for (TableModel tableModel : tables) { if (tableModel.getName().equalsIgnoreCase(newTable.getName())) { tableNameAlreadyExists = true; break; } } if (!tableNameAlreadyExists) { tables.add(newTable); ArrayList<TreeNode> treeNodeColletion = new ArrayList<TreeNode>(); treeNodeColletion.addAll(Arrays.asList((TreeNode[]) viewer.getInput())); TreeNode treeNode = new TreeNode(newTable); treeNodeColletion.add(treeNode); viewer.setInput(treeNodeColletion.toArray(new TreeNode[0])); tableAdded = true; } else { MessageDialog.openError(getShell(), DbCoreNLS.CreateDatabaseWizardPage_Table_Already_Exists_Title, NLS.bind(DbCoreNLS.CreateDatabaseWizardPage_Table_Already_Exists_Msg, newTable.getName())); } } } else { break; } } } }); editButton = new Button(buttonBar, SWT.PUSH); editButton.setText(DbCoreNLS.CreateDatabaseWizardPage_Edit_Button); editButton.setEnabled(false); editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TreeNode selectedNode = null; if (viewer.getSelection() instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) viewer.getSelection(); selectedNode = (TreeNode) treeSelection.getFirstElement(); TableModel table = (TableModel) selectedNode.getValue(); CreateTableWizard createTableWizard = new CreateTableWizard(); createTableWizard.init(table); WizardDialog dialog = new WizardDialog(getShell(), createTableWizard); dialog.open(); TableModel newTable = createTableWizard.getTable(); if (newTable != null) { tables.add(newTable); } viewer.refresh(); } } }); removeButton = new Button(buttonBar, SWT.PUSH); removeButton.setText(DbCoreNLS.CreateDatabaseWizardPage_Remove_Button); removeButton.setEnabled(false); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ArrayList<TreeNode> treeNodeColletion = new ArrayList<TreeNode>(); treeNodeColletion.addAll(Arrays.asList((TreeNode[]) viewer.getInput())); TreeNode selectedNode = null; if (viewer.getSelection() instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) viewer.getSelection(); selectedNode = (TreeNode) treeSelection.getFirstElement(); treeNodeColletion.remove(selectedNode); viewer.setInput(treeNodeColletion.toArray(new TreeNode[0])); } } }); composite.pack(); composite.layout(); setPageComplete(false); setErrorMessage(null); setControl(composite); PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, DATABASE_CONTEXT_HELP_ID); PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, DATABASE_CONTEXT_HELP_ID); }
From source file:com.nokia.carbide.cdt.internal.api.builder.ui.BrokenConfigurationInProjectTreeNode.java
License:Open Source License
/** * Constructs a new tree node for the given SDK * @param value the SDK to create the tree node for *//*from w w w .j a v a 2 s. c om*/ public BrokenConfigurationInProjectTreeNode(ISymbianSDK value, ICarbideProjectInfo cpi) { super(value); ArrayList<ISymbianBuildContext> childConfig = new ArrayList<ISymbianBuildContext>(); List<ICarbideBuildConfiguration> buildConfigList = cpi.getBuildConfigurations(); for (ICarbideBuildConfiguration config : buildConfigList) { if (config.getSDK().getUniqueId().equals(value.getUniqueId())) { childConfig.add(config.getBuildContext()); } } TreeNode[] children = new TreeNode[childConfig.size()]; int index = 0; for (ISymbianBuildContext buildContext : childConfig) { children[index++] = new TreeNode(buildContext) { @Override public String toString() { ISymbianBuildContext context = (ISymbianBuildContext) getValue(); return context.getDisplayString(); } }; } setChildren(children); }
From source file:com.nokia.carbide.cdt.internal.api.builder.ui.ManageConfigurationsDialog.java
License:Open Source License
/** * When displaying build configs there may be configurations in the project that may not be displayed * We add those back in so they reside in the checked tree viewer in case the user wants to remove them. * @param sdkConfigTreeNodes/*from w w w . ja v a 2 s. c o m*/ */ private void replaceFilteredConfigsFromProject(BuildTargetTreeNode[] sdkConfigTreeNodes) { if (sdkConfigTreeNodes == null) { return; } List<ICarbideBuildConfiguration> bldConfigs = cpi.getBuildConfigurations(); HashMap<BuildTargetTreeNode, List<ISymbianBuildContext>> missingConfigMap = new HashMap<BuildTargetTreeNode, List<ISymbianBuildContext>>(); for (ICarbideBuildConfiguration config : bldConfigs) { boolean foundConfig = false; // Add in configs that are only defined in the project and not the // suggested filtered config cache for (BuildTargetTreeNode sdkConfigNode : sdkConfigTreeNodes) { ISymbianSDK sdk = sdkConfigNode.getSymbianSDK(); if (!sdk.getUniqueId().equals(config.getSDK().getUniqueId())) { continue; // not in this SDK, don't bother looking at all configs } else { // Found the right SDK, now check and see if the config exists TreeNode[] configNodes = sdkConfigNode.getChildren(); if (configNodes != null) { for (TreeNode childConfig : configNodes) { if (childConfig == null) { continue; } if (childConfig.getValue() instanceof ISymbianBuildContext) { ISymbianBuildContext context = (ISymbianBuildContext) (childConfig.getValue()); if (config.getBuildContext().equals(context)) { foundConfig = true; break; } } } } if (!foundConfig) { // save config off, we'll add it back in later List<ISymbianBuildContext> contextsToAdd = new ArrayList<ISymbianBuildContext>(); if (null == missingConfigMap.get(sdkConfigNode)) { contextsToAdd.add(config.getBuildContext()); } else { contextsToAdd = missingConfigMap.get(sdkConfigNode); contextsToAdd.add(config.getBuildContext()); } missingConfigMap.put(sdkConfigNode, contextsToAdd); } } } } for (BuildTargetTreeNode sdkNode : missingConfigMap.keySet()) { List<ISymbianBuildContext> configsToAdd = missingConfigMap.get(sdkNode); TreeNode[] oldConfigNodes = sdkNode.getChildren(); if (oldConfigNodes == null || oldConfigNodes.length == 0) { continue; } TreeNode[] newConfigNodes = new TreeNode[oldConfigNodes.length + configsToAdd.size()]; int index = 0; // build up the old list.... for (TreeNode newConfigNode : oldConfigNodes) { if (newConfigNode == null) { continue; } if (newConfigNode.getValue() instanceof ISymbianBuildContext) { ISymbianBuildContext context = (ISymbianBuildContext) (newConfigNode.getValue()); newConfigNodes[index++] = new TreeNode(context) { @Override public String toString() { ISymbianBuildContext context = (ISymbianBuildContext) getValue(); String sdkId = context.getSDK().getUniqueId(); String newDisplayString = stripSDKIDFromConfigName(context.getDisplayString(), sdkId); if (context instanceof ISBSv2BuildContext) { ISBSv2BuildContext v2Context = (ISBSv2BuildContext) context; if (v2Context.getConfigQueryData() == null) { newDisplayString += " ERROR: " + "Unable to load configuration data because the query to sbs failed."; // $NON-NLS-N$ } else if (v2Context.getConfigQueryData().getConfigurationErrorMessage() != null && v2Context.getConfigQueryData().getConfigurationErrorMessage() .length() > 0) { newDisplayString += " ERROR: " + v2Context.getConfigQueryData().getConfigurationErrorMessage(); } } return newDisplayString; } }; } } // ... then add the project specific items... for (ISymbianBuildContext newContext : configsToAdd) { newConfigNodes[index++] = new TreeNode(newContext) { @Override public String toString() { ISymbianBuildContext context = (ISymbianBuildContext) getValue(); String sdkId = context.getSDK().getUniqueId(); String newDisplayString = stripSDKIDFromConfigName(context.getDisplayString(), sdkId); if (context instanceof ISBSv2BuildContext) { ISBSv2BuildContext v2Context = (ISBSv2BuildContext) context; if (v2Context.getConfigQueryData() == null) { newDisplayString += " ERROR: " + "Unable to load configuration data because the query to sbs failed."; // $NON-NLS-N$ } else if (v2Context.getConfigQueryData().getConfigurationErrorMessage() != null && v2Context.getConfigQueryData().getConfigurationErrorMessage().length() > 0) { newDisplayString += " ERROR: " + v2Context.getConfigQueryData().getConfigurationErrorMessage(); } } return newDisplayString; } }; } sdkNode.setChildren(newConfigNodes); } }
From source file:com.nokia.carbide.cpp.sdk.ui.shared.BuildTargetTreeNode.java
License:Open Source License
/** * Constructs a new tree node for the given SDK * @param value the SDK to create the tree node for * @since 1.4/* w w w .j a va2 s .c o m*/ */ public BuildTargetTreeNode(ISymbianSDK value, boolean sbsv2Project) { super(value); List<ISymbianBuildContext> configurations = sbsv2Project ? value.getBuildInfo(ISymbianBuilderID.SBSV2_BUILDER).getFilteredBuildConfigurations() : value.getBuildInfo(ISymbianBuilderID.SBSV1_BUILDER).getFilteredBuildConfigurations(); if (configurations == null) { return; } TreeNode[] children = new TreeNode[configurations.size()]; int index = 0; for (ISymbianBuildContext config : configurations) { children[index++] = new TreeNode(config) { @Override public String toString() { ISymbianBuildContext context = (ISymbianBuildContext) getValue(); String sdkId = context.getSDK().getUniqueId(); String newDisplayString = stripSDKIDFromConfigName(context.getDisplayString(), sdkId); if (context instanceof ISBSv2BuildContext) { ISBSv2BuildContext v2Context = (ISBSv2BuildContext) context; if (v2Context.getConfigQueryData().getConfigurationErrorMessage() != null && v2Context.getConfigQueryData().getConfigurationErrorMessage().length() > 0) { newDisplayString += " ERROR: " + v2Context.getConfigQueryData().getConfigurationErrorMessage(); } } return newDisplayString; } }; } setChildren(children); }