protected void cfgChanged(ICConfigurationDescription _cfgd) { CConfigurationStatus st = _cfgd.getConfigurationStatus(); if (errPane != null && errMessage != null) { if (st.isOK()) { errPane.setVisible(false); } else { errMessage.setText(st.getMessage()); errPane.setVisible(true); } } resd = getResDesc(_cfgd); if (excludeFromBuildCheck != null) { excludeFromBuildCheck.setEnabled(resd.canExclude(!resd.isExcluded())); excludeFromBuildCheck.setSelection(resd.isExcluded()); } int x = CDTPropertyManager.getPagesCount(); for (int i = 0; i < x; i++) { Object p = CDTPropertyManager.getPage(i); if (p == null || !(p instanceof AbstractPage)) continue; AbstractPage ap = (AbstractPage) p; if (ap.displayedConfig) ap.forEach(ICPropertyTab.UPDATE, getResDesc()); } }
private void populateConfigurations() { IProject prj = getProject(); // Do nothing in case of Preferences page. if (prj == null) return; // Do not re-read if list already created by another page if (cfgDescs == null) { ICProjectDescription pDesc = CDTPropertyManager.getProjectDescription(this, prj); cfgDescs = (pDesc == null) ? null : pDesc.getConfigurations(); if (cfgDescs == null || cfgDescs.length == 0) return; Arrays.sort(cfgDescs, CDTListComparator.getInstance()); } else { if (cfgDescs.length == 0) return; // just register in CDTPropertyManager; CDTPropertyManager.getProjectDescription(this, prj); } // Do nothing if widget not created yet. if (configSelector == null) { lastSelectedCfg = cfgDescs[getActiveCfgIndex()]; cfgChanged(lastSelectedCfg); return; } // Clear and replace the contents of the selector widget configSelector.removeAll(); for (int i = 0; i < cfgDescs.length; ++i) { String name = cfgDescs[i].getName(); if (cfgDescs[i].isActive()) { name = name + " " + Messages.AbstractPage_16; // $NON-NLS-1$ } configSelector.add(name); } // Ensure that the last selected config is selected by default int cfgIndex = getCfgIndex(lastSelectedCfg); // "All cfgs" - shown if at least 2 cfgs available if (cfgDescs.length > 1) { configSelector.add(Messages.AbstractPage_4); if (multiCfgs == cfgDescs) { cfgIndex = cfgDescs.length; } } // "Multi cfgs" - shown if at least 3 cfgs available if (cfgDescs.length > 2) { configSelector.add(Messages.AbstractPage_5); if (multiCfgs != null && multiCfgs != cfgDescs) { cfgIndex = cfgDescs.length + 1; } } if (cfgIndex < 0) { cfgIndex = getActiveCfgIndex(); } configSelector.select(cfgIndex); handleConfigSelection(); }
@Override public void informPages(int code, Object data) { for (int i = 0; i < CDTPropertyManager.getPagesCount(); i++) { Object p = CDTPropertyManager.getPage(i); if (p == null || !(p instanceof AbstractPage)) continue; AbstractPage ap = (AbstractPage) p; ap.handleMessage(code, data); } }
/** Default constructor */ public AbstractPage() { if (CDTPropertyManager.getPagesCount() == 0) { cfgDescs = null; lastSelectedCfg = null; multiCfgs = null; } }
@Override public boolean performCancel() { if (!noContentOnPage && displayedConfig) forEach(ICPropertyTab.CANCEL); CDTPropertyManager.performCancel(this); return true; }
@Override public void dispose() { // Dispose the tabs if (displayedConfig) forEach(ICPropertyTab.DISPOSE); // Dispose any loaded images for (Image img : loadedIcons.values()) img.dispose(); loadedIcons.clear(); if (!isNewOpening) handleResize(false); // save page size isNewOpening = true; // Remove this page from the property manager CDTPropertyManager.remove(this); // clear static variables if (CDTPropertyManager.getPagesCount() == 0) { resd = null; cfgDescs = null; } }
/** The same code used to perform OK and Apply */ private boolean performSave(int mode) { final int finalMode = mode; if (noContentOnPage || !displayedConfig) return true; if ((mode == SAVE_MODE_OK || mode == SAVE_MODE_APPLYOK) && CDTPropertyManager.isSaveDone()) return true; // do not duplicate final boolean needs = (mode != SAVE_MODE_OK); final ICProjectDescription local_prjd = needs ? CoreModel.getDefault().getProjectDescription(getProject()) : null; ICResourceDescription lc = null; if (needs) { if (isMultiCfg()) { ICResourceDescription[] rds = (ICResourceDescription[]) ((ICMultiItemsHolder) resd).getItems(); for (int i = 0; i < rds.length; i++) { ICConfigurationDescription c = local_prjd.getConfigurationById(rds[i].getConfiguration().getId()); rds[i] = getResDesc(c); } lc = MultiItemsHolder.createRDescription(rds); } else { ICConfigurationDescription c = findCfg(local_prjd, resd.getConfiguration()); if (c == null) return false; // cannot save: no cfg found lc = getResDesc(c); } } final ICResourceDescription local_cfgd = lc; final boolean rebuildIndex = isIndexerAffected(); IRunnableWithProgress runnable = new IRunnableWithProgress() { private void sendOK() { for (int j = 0; j < CDTPropertyManager.getPagesCount(); j++) { Object p = CDTPropertyManager.getPage(j); if (p != null && p instanceof AbstractPage) { AbstractPage ap = (AbstractPage) p; if (ap.displayedConfig) ap.forEach(ICPropertyTab.OK, null); } } } @Override public void run(IProgressMonitor monitor) { // ask all tabs to store changes in cfg switch (finalMode) { case SAVE_MODE_APPLYOK: sendOK(); ICConfigurationDescription[] olds = CDTPropertyManager.getProjectDescription(AbstractPage.this, getProject()) .getConfigurations(); for (ICConfigurationDescription old : olds) { resd = getResDesc(old); ICResourceDescription r = getResDesc(local_prjd.getConfigurationById(old.getId())); for (int j = 0; j < CDTPropertyManager.getPagesCount(); j++) { Object p = CDTPropertyManager.getPage(j); if (p != null && p instanceof AbstractPage) { AbstractPage ap = (AbstractPage) p; if (ap.displayedConfig) { ap.forEach(ICPropertyTab.UPDATE, resd); ap.forEach(ICPropertyTab.APPLY, r); } } } } break; case SAVE_MODE_APPLY: forEach(ICPropertyTab.APPLY, local_cfgd); break; case SAVE_MODE_OK: sendOK(); break; } // end switch try { if (needs) // CoreModel.getDefault().setProjectDescription(getProject(), local_prjd); else CDTPropertyManager.performOk(AbstractPage.this); } catch (CoreException e) { CUIPlugin.logError(Messages.AbstractPage_11 + e.getLocalizedMessage()); } updateViews(internalElement); } }; IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); try { PlatformUI.getWorkbench() .getProgressService() .runInUI( new ProgressMonitorDialog(getShell()), op, ResourcesPlugin.getWorkspace().getRoot()); } catch (InvocationTargetException e) { Throwable e1 = e.getTargetException(); CUIPlugin.errorDialog(getShell(), Messages.AbstractPage_8, Messages.AbstractPage_9, e1, true); return false; } catch (InterruptedException e) { // IProgressService.runInUI(...) misuses this exception to signal that the operation was // canceled. return false; } if (rebuildIndex) rebuildIndex(); return true; }