[Mantisconnect-cvs] SF.net SVN: mantisconnect: [110] mantisconnect/trunk/clients/java/eclipse/ org
Brought to you by:
vboctor
From: <pl...@us...> - 2007-03-05 16:10:44
|
Revision: 110 http://svn.sourceforge.net/mantisconnect/?rev=110&view=rev Author: planser Date: 2007-03-05 08:10:39 -0800 (Mon, 05 Mar 2007) Log Message: ----------- Added support for subprojects Modified Paths: -------------- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettings.java mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettingsRegistry.java mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/MantisConnectView.java mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsLabelProvider.java mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/UpdateProjectsRunnable.java Added Paths: ----------- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectDataNode.java mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsContentProvider.java Modified: mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettings.java =================================================================== --- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettings.java 2007-03-05 16:05:19 UTC (rev 109) +++ mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettings.java 2007-03-05 16:10:39 UTC (rev 110) @@ -74,7 +74,7 @@ private boolean savePassword; - private int lastProjectId; + private String lastProjectIdPath; private Map<Integer, Integer> filters = new HashMap<Integer, Integer>(); @@ -83,18 +83,18 @@ } public ConnectionSettings(String name, URL mantisConnectUrl) { - this(name, mantisConnectUrl, null, null, null, false, -1, new HashMap<Integer, Integer>()); + this(name, mantisConnectUrl, null, null, null, false, null, new HashMap<Integer, Integer>()); } public ConnectionSettings(String name, URL mantisConnectUrl, URL browserUrl, String user, - String password, boolean savePassword, int lastProjectId, Map<Integer, Integer> filters) { + String password, boolean savePassword, String lastProjectIdPath, Map<Integer, Integer> filters) { this.name = name; this.mantisConnectUrl = mantisConnectUrl; this.browserUrl = browserUrl; this.user = user; this.password = password; this.savePassword = savePassword; - this.lastProjectId = lastProjectId; + this.lastProjectIdPath = lastProjectIdPath; this.filters = filters; } @@ -118,8 +118,8 @@ return user; } - public int getLastProjectId() { - return lastProjectId; + public String getLastProjectIdPath() { + return lastProjectIdPath; } public int getLastFilterId(int projectId) { @@ -167,8 +167,8 @@ return savePassword; } - public void setLastProjectId(int lastProjectId) { - this.lastProjectId = lastProjectId; + public void setLastProjectIdPath(String lastProjectIdPath) { + this.lastProjectIdPath = lastProjectIdPath; } public void setLastFilterId(int projectId, int lastFilterId) { @@ -234,7 +234,7 @@ public Object clone() { return new ConnectionSettings(getName(), getMantisConnectUrl(), getBrowserUrl(), getUser(), - getPassword(), isSavePassword(), getLastProjectId(), getFilters()); + getPassword(), isSavePassword(), getLastProjectIdPath(), getFilters()); } public URL getUrlForIssue(IssueHeaderData issue, ProjectData project) { Modified: mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettingsRegistry.java =================================================================== --- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettingsRegistry.java 2007-03-05 16:05:19 UTC (rev 109) +++ mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/ConnectionSettingsRegistry.java 2007-03-05 16:10:39 UTC (rev 110) @@ -39,25 +39,25 @@ private static final String TAG_NAME = "name"; private static final String TAG_MANTISCONNECT_URL = "url"; - + private static final String TAG_BROWSER_URL = "browser-url"; private static final String TAG_USER = "user"; private static final String TAG_PASSWORD = "password"; - + private static final String TAG_LAST_PROJECT_ID = "last-project-id"; - + private static final String TAG_PROJECT_FILTERS = "project-filters"; - + private static final String TAG_PROJECT_ID = "project-id"; - + private static final String TAG_FILTER_ID = "filter-id"; private static ConnectionSettingsRegistry instance; private Map<String, ConnectionSettings> map = new HashMap<String, ConnectionSettings>(); - + private ConnectionSettingsRegistry() { } @@ -75,7 +75,7 @@ String mantisUrl = connections[i].getString(TAG_BROWSER_URL); String user = connections[i].getString(TAG_USER); String password = connections[i].getString(TAG_PASSWORD); - Integer lastProjectId = connections[i].getInteger(TAG_LAST_PROJECT_ID); + String lastProjectId = connections[i].getString(TAG_LAST_PROJECT_ID); IMemento[] filters = connections[i].getChildren(TAG_PROJECT_FILTERS); Map<Integer, Integer> filterMap = new HashMap<Integer, Integer>(); for (int j = 0; j < filters.length; j++) { @@ -88,7 +88,7 @@ map.put(name, new ConnectionSettings(name, mantisConnectUrl, mantisUrl != null ? new URL(mantisUrl) : null, isEmpty(user) ? null : user, isEmpty(password) ? null : password, !isEmpty(password), - lastProjectId != null ? lastProjectId : -1, filterMap)); + isEmpty(lastProjectId) ? null : lastProjectId , filterMap)); } } @@ -109,7 +109,7 @@ memento.putString(TAG_BROWSER_URL, connection.getBrowserUrl().toString()); } memento.putString(TAG_USER, connection.getUser()); - memento.putInteger(TAG_LAST_PROJECT_ID, connection.getLastProjectId()); + memento.putString(TAG_LAST_PROJECT_ID, connection.getLastProjectIdPath()); if (connection.isSavePassword()) { memento.putString(TAG_PASSWORD, connection.getPassword()); } else { @@ -128,7 +128,7 @@ getPreferenceStore().setValue(MantisConnectPlugin.PREF_CONNECTIONS, sw.getBuffer().toString()); } - + public ConnectionSettings getConnection(String name) { ConnectionSettings result = (ConnectionSettings) map.get(name); if (result != null) { @@ -137,19 +137,20 @@ return null; } } - + public ConnectionSettings[] getConnections() { ConnectionSettings[] result = new ConnectionSettings[map.size()]; Iterator iterator = map.entrySet().iterator(); int pos = 0; while (iterator.hasNext()) { - ConnectionSettings connection = (ConnectionSettings) ((Map.Entry) iterator.next()).getValue(); + ConnectionSettings connection = (ConnectionSettings) ((Map.Entry) iterator.next()) + .getValue(); result[pos] = (ConnectionSettings) connection.clone(); pos += 1; } return result; } - + public void setConnections(ConnectionSettings[] connections) throws IOException { map.clear(); for (int i = 0; i < connections.length; i++) { Modified: mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/MantisConnectView.java =================================================================== --- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/MantisConnectView.java 2007-03-05 16:05:19 UTC (rev 109) +++ mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/MantisConnectView.java 2007-03-05 16:10:39 UTC (rev 110) @@ -91,13 +91,13 @@ * @author Peter Lanser, pl...@us... */ public class MantisConnectView extends ViewPart implements IssueViewer { - + public static String ID = "org.mantisbt.connect.eclipse.views.MantisConnectView"; private static final String TAG_CURRENT_CONNECTION = "current-connection"; - + private static final String TAG_LAST_SORTED_COLUMN = "last-sorted-column"; - + private static final String TAG_LAST_SORTED_ASC = "last-sorted-asc"; private static final String TAG_VERTICAL_POSITION = "verticalPosition"; @@ -134,40 +134,40 @@ new ColumnWeightData(800), // Summary }; - private final static String[] COLUMN_HEADERS = { "", "", "ID", "#", - "Category", "Severity", "Status", "Updated", "Summary" }; + private final static String[] COLUMN_HEADERS = { "", "", "ID", "#", "Category", "Severity", + "Status", "Updated", "Summary" }; - private final static int[] COLUMN_STYLES = { SWT.NONE, SWT.NONE, SWT.RIGHT, - SWT.RIGHT, SWT.NONE, SWT.NONE, SWT.NONE, SWT.RIGHT, SWT.NONE }; + private final static int[] COLUMN_STYLES = { SWT.NONE, SWT.NONE, SWT.RIGHT, SWT.RIGHT, + SWT.NONE, SWT.NONE, SWT.NONE, SWT.RIGHT, SWT.NONE }; private IMemento memento; private ConnectionSettings currentConnection; - + private ContributionWrapper[] issueViewerContributions; private ColumnLayoutData[] columnLayouts; private IssuesSorter sorter; - + private TableViewer issues; - + private IssuesPatternFilter viewerFilter; private ComboViewer projects; private ComboViewer filters; - + private Text filterText; - + private ToolBarManager clearButtonToolbar; - + private Label sessionInfo; private ISession session; private RefreshIssuesJob refreshIssuesJob; - + private RefreshAction refreshAction; private NewIssueAction newIssueAction; @@ -178,58 +178,50 @@ super.init(site, memento); this.memento = memento; if (memento != null) { - currentConnection = ConnectionSettingsRegistry.getInstance() - .getConnection(memento.getString(TAG_CURRENT_CONNECTION)); + currentConnection = ConnectionSettingsRegistry.getInstance().getConnection( + memento.getString(TAG_CURRENT_CONNECTION)); } - MantisConnectPlugin.getDefault().getPreferenceStore() - .addPropertyChangeListener(new IPropertyChangeListener() { + MantisConnectPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( + new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { - if (event - .getProperty() - .equals( - MantisConnectPlugin.PREF_REFRESH_INTERVAL_IN_MS)) { + if (event.getProperty().equals( + MantisConnectPlugin.PREF_REFRESH_INTERVAL_IN_MS)) { scheduleRefreshJob(getRefreshIntervallInMs()); - } else if (event.getProperty().equals( - MantisConnectPlugin.PREF_LIMIT)) { + } else if (event.getProperty().equals(MantisConnectPlugin.PREF_LIMIT)) { updateIssues(); - } else if (event.getProperty().equals( - MantisConnectPlugin.PREF_CHANGED)) { + } else if (event.getProperty().equals(MantisConnectPlugin.PREF_CHANGED)) { ((IssuesLabelProvider) issues.getLabelProvider()) .setChanged(getChanged()); issues.refresh(); - } else if (event.getProperty().equals( - MantisConnectPlugin.PREF_CONNECTIONS)) { + } else if (event.getProperty().equals(MantisConnectPlugin.PREF_CONNECTIONS)) { if (getCurrentConnectionSettings() != null) { - String currentName = getCurrentConnectionSettings() - .getName(); + String currentName = getCurrentConnectionSettings().getName(); ConnectionSettings settings = ConnectionSettingsRegistry - .getInstance().getConnection( - currentName); + .getInstance().getConnection(currentName); setCurrentConnectionSettings(settings, false); } } } }); - IConfigurationElement[] elements = Platform.getExtensionRegistry() - .getConfigurationElementsFor( - "org.mantisbt.connect.eclipse.issueViewerContribution"); + IConfigurationElement[] elements = Platform + .getExtensionRegistry() + .getConfigurationElementsFor("org.mantisbt.connect.eclipse.issueViewerContribution"); ArrayList<ContributionWrapper> contributions = new ArrayList<ContributionWrapper>(); for (int i = 0; i < elements.length; i++) { try { IIssueViewerContribution contribution = (IIssueViewerContribution) elements[i] .createExecutableExtension("class"); contribution.init(this); - int columns = Integer.parseInt(elements[i] - .getAttribute("columns")); - String pluginId = ((org.eclipse.core.runtime.IExtension) elements[i] - .getParent()).getUniqueIdentifier(); + int columns = Integer.parseInt(elements[i].getAttribute("columns")); + String pluginId = ((org.eclipse.core.runtime.IExtension) elements[i].getParent()) + .getUniqueIdentifier(); ContributionWrapper.Position position = ContributionWrapper.Position .fromString(elements[i].getAttribute("position")); - contributions.add(new ContributionWrapper( - contribution, pluginId, columns, position)); + contributions + .add(new ContributionWrapper(contribution, pluginId, columns, position)); } catch (CoreException e) { - MantisConnectPlugin.getDefault().error( - "Could not create IssueViewerContribution", e, true); + MantisConnectPlugin.getDefault().error("Could not create IssueViewerContribution", + e, true); } } issueViewerContributions = (ContributionWrapper[]) contributions @@ -261,8 +253,9 @@ ContributionWrapper[] end = getIssueViewerContributions(ContributionWrapper.Position.END); for (int i = 0; i < end.length; i++) { for (int j = 0; j < end[i].getColumnCount(); j++) { - memento.putInteger("column." + end[i].getId() + "." + j, columns[offset] - .getWidth()); + memento + .putInteger("column." + end[i].getId() + "." + j, columns[offset] + .getWidth()); offset += 1; } } @@ -297,7 +290,7 @@ topControls.setLayoutData(gd); new Label(topControls, SWT.NONE).setText("Project:"); projects = new ComboViewer(topControls, SWT.READ_ONLY); - projects.setContentProvider(new SimpleViewerContentProvider()); + projects.setContentProvider(new ProjectsContentProvider()); projects.setLabelProvider(new ProjectsLabelProvider()); projects.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { @@ -385,7 +378,7 @@ setCurrentConnectionSettings(currentConnection, false); scheduleRefreshJob(getRefreshIntervallInMs()); } - + private String getInitialFilterText() { return "type filter text"; } @@ -393,57 +386,56 @@ private Text createFilterText(Composite topControls) { filterText = new Text(topControls, SWT.BORDER); filterText.setText(getInitialFilterText()); - filterText.addFocusListener( - new FocusAdapter(){ - public void focusGained(FocusEvent e) { - /* Running in an asyncExec because the selectAll() does not - * appear to work when using mouse to give focus to text. - */ - Display display = filterText.getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - if (!filterText.isDisposed()){ - if (getInitialFilterText().equals(filterText.getText().trim())){ - filterText.selectAll(); - } - } - } - }); + filterText.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + /* Running in an asyncExec because the selectAll() does not + * appear to work when using mouse to give focus to text. + */ + Display display = filterText.getDisplay(); + display.asyncExec(new Runnable() { + public void run() { + if (!filterText.isDisposed()) { + if (getInitialFilterText().equals(filterText.getText().trim())) { + filterText.selectAll(); + } + } } }); - filterText.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - // on a CR we want to transfer focus to the list - boolean hasItems = issues.getTable().getItemCount() > 0; - if(hasItems && e.keyCode == SWT.ARROW_DOWN){ - issues.getTable().setFocus(); - } else if (e.character == SWT.CR){ + } + }); + filterText.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + // on a CR we want to transfer focus to the list + boolean hasItems = issues.getTable().getItemCount() > 0; + if (hasItems && e.keyCode == SWT.ARROW_DOWN) { + issues.getTable().setFocus(); + } else if (e.character == SWT.CR) { return; - } - } - }); - filterText.addModifyListener(new ModifyListener(){ - public void modifyText(ModifyEvent e) { - filterTextChanged(); - } - }); + } + } + }); + filterText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + filterTextChanged(); + } + }); return filterText; } - + private void filterTextChanged() { String text = filterText.getText().trim(); viewerFilter.setPattern(text); issues.refresh(); updateClearButton(text.length() > 0); } - - private void createClearButton(Composite parent) { - ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL); + + private void createClearButton(Composite parent) { + ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL); clearButtonToolbar = new ToolBarManager(toolBar); IAction clearTextAction = new Action("", IAction.AS_PUSH_BUTTON) {//$NON-NLS-1$ public void run() { - filterText.setText(""); //$NON-NLS-1$ - filterTextChanged(); + filterText.setText(""); //$NON-NLS-1$ + filterTextChanged(); } }; clearTextAction.setToolTipText("Clear"); @@ -451,12 +443,12 @@ .getDescriptor(MantisConnectPlugin.IMG_CLEAR_16)); clearButtonToolbar.add(clearTextAction); clearButtonToolbar.update(false); - } - - private void updateClearButton(boolean visible) { - clearButtonToolbar.getControl().setVisible(visible); - } - + } + + private void updateClearButton(boolean visible) { + clearButtonToolbar.getControl().setVisible(visible); + } + private void hookContextMenu() { MenuManager menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); @@ -469,7 +461,7 @@ issues.getControl().setMenu(menu); getSite().registerContextMenu(menuMgr, issues); } - + private void fillContextMenu(IMenuManager manager) { // Other plug-ins can contribute there actions here manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); @@ -485,10 +477,8 @@ refreshIssuesJob.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if (event.getResult() != Status.CANCEL_STATUS) { - IssueHeaderData[] data = ((RefreshIssuesJob) event - .getJob()).getData(); - updateViewer(new UpdateIssuesRunnable(data, issues, - MantisConnectView.this)); + IssueHeaderData[] data = ((RefreshIssuesJob) event.getJob()).getData(); + updateViewer(new UpdateIssuesRunnable(data, issues, MantisConnectView.this)); } } }); @@ -500,17 +490,14 @@ FilterData filter = getCurrentFilter(); issues.getTable().clearAll(); if (filter != null) { - FetchIssuesJob job = new FetchIssuesJob(session, - getCurrentProject().getId().longValue(), filter.getId() - .longValue(), getLimit()); + FetchIssuesJob job = new FetchIssuesJob(session, getCurrentProject().getId() + .longValue(), filter.getId().longValue(), getLimit()); job.setUser(false); job.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if (event.getResult().isOK()) { - IssueHeaderData[] data = ((FetchIssuesJob) event.getJob()) - .getData(); - updateViewer(new UpdateIssuesRunnable(data, issues, - MantisConnectView.this)); + IssueHeaderData[] data = ((FetchIssuesJob) event.getJob()).getData(); + updateViewer(new UpdateIssuesRunnable(data, issues, MantisConnectView.this)); } else { clearUI(); } @@ -593,7 +580,7 @@ } }; } - + private IssuesSorter restoreSorter(IMemento memento) { IssuesSorter sorter = new IssuesSorter(this, getColumnIndex("column." + MantisConnectPlugin.getDefault().getBundle().getSymbolicName() + "." @@ -613,7 +600,7 @@ } return sorter; } - + private String getColumnId(int idx) { ContributionWrapper[] start = getIssueViewerContributions(ContributionWrapper.Position.START); int offset = 0; @@ -625,7 +612,8 @@ } } if (idx < offset + DEFAULT_COLUMN_LAYOUTS.length) { - return "column." + MantisConnectPlugin.getDefault().getBundle().getSymbolicName() + "." + (idx - offset); + return "column." + MantisConnectPlugin.getDefault().getBundle().getSymbolicName() + "." + + (idx - offset); } offset += DEFAULT_COLUMN_LAYOUTS.length; ContributionWrapper[] end = getIssueViewerContributions(ContributionWrapper.Position.END); @@ -636,10 +624,10 @@ offset += end[i].getColumnCount(); } } - + return null; } - + private int getColumnIndex(String columnId) { ContributionWrapper[] start = getIssueViewerContributions(ContributionWrapper.Position.START); int firstSep = columnId.indexOf('.'); @@ -673,22 +661,20 @@ } } else { offset += end[i].getColumnCount(); - } + } } } return -1; } - - private ContributionWrapper[] getIssueViewerContributions( - ContributionWrapper.Position position) { + + private ContributionWrapper[] getIssueViewerContributions(ContributionWrapper.Position position) { ArrayList<ContributionWrapper> result = new ArrayList<ContributionWrapper>(); for (int i = 0; i < issueViewerContributions.length; i++) { if (issueViewerContributions[i].getPosition().equals(position)) { result.add(issueViewerContributions[i]); } } - return (ContributionWrapper[]) result - .toArray(new ContributionWrapper[result.size()]); + return (ContributionWrapper[]) result.toArray(new ContributionWrapper[result.size()]); } private void restoreColumnWidths(IMemento memento) { @@ -712,16 +698,14 @@ getIssueViewerContributions(ContributionWrapper.Position.END), temp, memento); columnLayouts = (ColumnLayoutData[]) temp.toArray(new ColumnLayoutData[temp.size()]); } - - private void restoreIssueViewerContributorColumnWidths( - ContributionWrapper[] contributions, ArrayList<ColumnLayoutData> list, - IMemento memento) { + + private void restoreIssueViewerContributorColumnWidths(ContributionWrapper[] contributions, + ArrayList<ColumnLayoutData> list, IMemento memento) { for (int i = 0; i < contributions.length; i++) { for (int j = 0; j < contributions[i].getColumnCount(); j++) { Integer width = null; if (memento != null) { - width = memento - .getInteger("column." + contributions[i].getId() + "." + j); + width = memento.getInteger("column." + contributions[i].getId() + "." + j); } if (width != null) { list.add(new ColumnPixelData(width, true)); @@ -750,13 +734,13 @@ public FilterData getCurrentFilter() { IStructuredSelection selection = (IStructuredSelection) filters.getSelection(); - if (! selection.isEmpty()) { + if (!selection.isEmpty()) { return (FilterData) selection.getFirstElement(); } else { return null; } } - + public void sessionChanged(final boolean showError) { newIssueAction.setEnabled(session != null); refreshAction.setEnabled(session != null); @@ -767,8 +751,8 @@ public void done(IJobChangeEvent event) { if (event.getResult().isOK()) { ProjectData[] result = fetchProjectsJob.getData(); - ProjectData selection = findProjectById(result, - getCurrentConnectionSettings().getLastProjectId()); + ProjectDataNode selection = ProjectDataNode.createByPath(result, + getCurrentConnectionSettings().getLastProjectIdPath()); updateViewer(new UpdateProjectsRunnable(result, selection, projects, MantisConnectView.this)); } else { @@ -789,15 +773,6 @@ } sessionInfo.getParent().layout(true); } - - private ProjectData findProjectById(ProjectData[] projects, int projectId) { - for (ProjectData project : projects) { - if (project.getId().intValue() == projectId) { - return project; - } - } - return null; - } public void filterChanged() { getCurrentConnectionSettings().setLastFilterId(getCurrentProject().getId().intValue(), @@ -811,15 +786,16 @@ } public void projectChanged() { - final ProjectData project = getCurrentProject(); - if (project != null) { - getCurrentConnectionSettings().setLastProjectId(project.getId().intValue()); + final ProjectDataNode projectNode = getCurrentProjectNode(); + if (projectNode != null) { + getCurrentConnectionSettings().setLastProjectIdPath(projectNode.getIdPath()); try { ConnectionSettingsRegistry.getInstance().update(getCurrentConnectionSettings()); } catch (IOException e) { // eat } - FetchFiltersJob job = new FetchFiltersJob(session, project.getId().longValue()); + FetchFiltersJob job = new FetchFiltersJob(session, projectNode.getProjectData().getId() + .longValue()); job.setUser(false); job.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { @@ -827,7 +803,7 @@ FilterData[] result = ((FetchFiltersJob) event.getJob()).getData(); FilterData selection = findFilterById(result, getCurrentConnectionSettings().getLastFilterId( - project.getId().intValue())); + projectNode.getProjectData().getId().intValue())); updateViewer(new UpdateFiltersRunnable(result, selection, filters, MantisConnectView.this)); } else { @@ -838,7 +814,7 @@ getProgressService().schedule(job); } } - + private FilterData findFilterById(FilterData[] filters, int filterId) { for (FilterData filter : filters) { if (filter.getId().intValue() == filterId) { @@ -847,16 +823,25 @@ } return null; } - - public ProjectData getCurrentProject() { + + public ProjectDataNode getCurrentProjectNode() { IStructuredSelection selection = (IStructuredSelection) projects.getSelection(); - if (! selection.isEmpty()) { - return (ProjectData) selection.getFirstElement(); + if (!selection.isEmpty()) { + return ((ProjectDataNode) selection.getFirstElement()); } else { return null; } } + public ProjectData getCurrentProject() { + ProjectDataNode projectDataNode = getCurrentProjectNode(); + if (projectDataNode != null) { + return projectDataNode.getProjectData(); + } else { + return null; + } + } + private void contributeToActionBars() { IActionBars bars = getViewSite().getActionBars(); fillLocalPullDown(bars.getMenuManager()); @@ -890,8 +875,7 @@ return currentConnection; } - public void setCurrentConnectionSettings(ConnectionSettings connection, - boolean explicit) { + public void setCurrentConnectionSettings(ConnectionSettings connection, boolean explicit) { currentConnection = connection; if (currentConnection != null && !connection.isComplete()) { if (explicit) { @@ -913,12 +897,11 @@ connection.setPassword(""); } try { - session = MantisConnectPlugin.getDefault().getSessionFactory() - .newSession(connection.getMantisConnectUrl(), connection.getUser(), - connection.getPassword()); + session = MantisConnectPlugin.getDefault().getSessionFactory().newSession( + connection.getMantisConnectUrl(), connection.getUser(), + connection.getPassword()); } catch (Exception e) { - MantisConnectPlugin.getDefault().error( - "Could not open session.", e, showError); + MantisConnectPlugin.getDefault().error("Could not open session.", e, showError); } } sessionChanged(showError); @@ -928,7 +911,7 @@ return (IWorkbenchSiteProgressService) getViewSite().getAdapter( IWorkbenchSiteProgressService.class); } - + public ISession getSession() { return session; } @@ -961,9 +944,9 @@ } }); } - + public IssueHeaderData[] getCurrentIssues() { return (IssueHeaderData[]) issues.getInput(); } - + } \ No newline at end of file Added: mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectDataNode.java =================================================================== --- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectDataNode.java (rev 0) +++ mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectDataNode.java 2007-03-05 16:10:39 UTC (rev 110) @@ -0,0 +1,91 @@ +package org.mantisbt.connect.eclipse.views; + +import java.util.StringTokenizer; + +import org.mantisbt.connect.service.ProjectData; + +public class ProjectDataNode { + + private ProjectData projectData; + + private ProjectDataNode parent; + + public ProjectDataNode(ProjectData projectData) { + this(projectData, null); + } + + public ProjectDataNode(ProjectData projectData, ProjectDataNode parent) { + this.projectData = projectData; + this.parent = parent; + } + + public int getLevel() { + if (parent != null) { + return parent.getLevel() + 1; + } else { + return 0; + } + } + + public ProjectData getProjectData() { + return projectData; + } + + public String toString() { + return new StringBuffer("Project: ").append(projectData.getName()).append(", Level: ") + .append(getLevel()).append(", IdPath: ").append(getIdPath()).toString(); + } + + public String getIdPath() { + StringBuffer buffer = new StringBuffer(); + if (parent != null) { + buffer.append(parent.getIdPath()).append("."); + } + return buffer.append(projectData.getId()).toString(); + } + + public int hashCode() { + return getIdPath().hashCode(); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final ProjectDataNode other = (ProjectDataNode) obj; + return getIdPath().equals(other.getIdPath()); + } + + public static ProjectDataNode createByPath(ProjectData[] initialProjects, String path) { + ProjectData[] projects = initialProjects; + if (path != null) { + StringTokenizer tokenizer = new StringTokenizer(path, "."); + ProjectDataNode parent = null; + while (tokenizer.hasMoreElements()) { + int id = Integer.parseInt(tokenizer.nextToken()); + ProjectData project = findProjectById(projects, id); + if (project != null) { + parent = new ProjectDataNode(project, parent); + projects = project.getSubprojects(); + } + } + + return parent; + } else { + return null; + } + } + + private static ProjectData findProjectById(ProjectData[] projects, int projectId) { + for (ProjectData project : projects) { + if (project.getId().intValue() == projectId) { + return project; + } + } + return null; + } + +} Added: mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsContentProvider.java =================================================================== --- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsContentProvider.java (rev 0) +++ mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsContentProvider.java 2007-03-05 16:10:39 UTC (rev 110) @@ -0,0 +1,47 @@ +package org.mantisbt.connect.eclipse.views; + +import java.util.ArrayList; +import java.util.Collections; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.mantisbt.connect.service.ProjectData; + +public class ProjectsContentProvider implements IStructuredContentProvider { + + private ProjectDataNode[] projects; + + public Object[] getElements(Object inputElement) { + return projects; + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput != null) { + ProjectData[] data = (ProjectData[]) newInput; + ArrayList<ProjectDataNode> elements = new ArrayList<ProjectDataNode>(); + for (int i = 0; i < data.length; i++) { + ProjectDataNode node = new ProjectDataNode(data[i]); + elements.add(node); + Collections.addAll(elements, findSubProjects(node)); + } + projects = (ProjectDataNode[]) elements.toArray(new ProjectDataNode[elements.size()]); + } else { + projects = new ProjectDataNode[0]; + } + } + + private ProjectDataNode[] findSubProjects(ProjectDataNode parent) { + ArrayList<ProjectDataNode> result = new ArrayList<ProjectDataNode>(); + ProjectData[] subProjects = parent.getProjectData().getSubprojects(); + for (int i = 0; i < subProjects.length; i++) { + ProjectDataNode node = new ProjectDataNode(subProjects[i], parent); + result.add(node); + Collections.addAll(result, findSubProjects(node)); + } + return (ProjectDataNode[]) result.toArray(new ProjectDataNode[result.size()]); + } + +} Modified: mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsLabelProvider.java =================================================================== --- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsLabelProvider.java 2007-03-05 16:05:19 UTC (rev 109) +++ mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/ProjectsLabelProvider.java 2007-03-05 16:10:39 UTC (rev 110) @@ -12,7 +12,6 @@ package org.mantisbt.connect.eclipse.views; import org.eclipse.jface.viewers.LabelProvider; -import org.mantisbt.connect.service.ProjectData; /** * @author Peter Lanser, pl...@us... @@ -20,7 +19,20 @@ public class ProjectsLabelProvider extends LabelProvider { public String getText(Object element) { - return ((ProjectData) element).getName(); + ProjectDataNode data = (ProjectDataNode) element; + return new StringBuffer(getPrefix(data)).append(data.getProjectData().getName()).toString(); } + private String getPrefix(ProjectDataNode data) { + if (data.getLevel() == 0) { + return ""; + } else { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < data.getLevel(); i++) { + buffer.append("-"); + } + return buffer.append(" ").toString(); + } + } + } Modified: mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/UpdateProjectsRunnable.java =================================================================== --- mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/UpdateProjectsRunnable.java 2007-03-05 16:05:19 UTC (rev 109) +++ mantisconnect/trunk/clients/java/eclipse/org.mantisbt.connect.eclipse/src/org/mantisbt/connect/eclipse/views/UpdateProjectsRunnable.java 2007-03-05 16:10:39 UTC (rev 110) @@ -21,10 +21,10 @@ */ public class UpdateProjectsRunnable extends UpdateViewerRunnable<ProjectData, ComboViewer> { - private ProjectData selectedObject; + private ProjectDataNode selectedObject; - public UpdateProjectsRunnable(ProjectData[] data, ProjectData selection, ComboViewer viewer, - MantisConnectView mantisView) { + public UpdateProjectsRunnable(ProjectData[] data, ProjectDataNode selection, + ComboViewer viewer, MantisConnectView mantisView) { super(data, viewer, mantisView); this.selectedObject = selection; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |