cdt/cdt_6_0_x/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/executables/ExecutablesContentProvider.java
author wpaul
Fri, 07 Aug 2009 13:47:27 -0500
changeset 60 3982fab6369e
parent 52 42077b7eab6e
permissions -rw-r--r--
fixed executables view merge problems - bug #'s 9562, 9568, 9571.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 * Nokia - Initial API and implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    10
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    11
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
package org.eclipse.cdt.debug.internal.ui.views.executables;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
import com.ibm.icu.text.DateFormat;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import java.util.Date;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    16
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
import org.eclipse.cdt.debug.core.executables.Executable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import org.eclipse.cdt.debug.core.executables.ExecutablesManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    19
import org.eclipse.core.runtime.IPath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import org.eclipse.jface.viewers.ColumnLabelProvider;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
import org.eclipse.jface.viewers.IStructuredContentProvider;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import org.eclipse.jface.viewers.ITreeContentProvider;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
import org.eclipse.jface.viewers.TreeViewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import org.eclipse.jface.viewers.Viewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
import org.eclipse.jface.viewers.ViewerCell;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
class ExecutablesContentProvider extends ColumnLabelProvider implements IStructuredContentProvider, ITreeContentProvider {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
	public ExecutablesContentProvider(TreeViewer viewer) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    32
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    33
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
	public void dispose() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
	public Object[] getElements(final Object inputElement) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
		if (inputElement instanceof ExecutablesManager) {
52
42077b7eab6e Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents: 51
diff changeset
    40
			ExecutablesManager em = (ExecutablesManager) inputElement;
42077b7eab6e Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents: 51
diff changeset
    41
			return em.getExecutables().toArray();
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    42
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
		return new Object[] {};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    44
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
	public Object getParent(Object element) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    48
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
	public boolean hasChildren(Object element) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
		return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    52
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    53
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    55
	public void update(ViewerCell cell) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
		super.update(cell);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    57
		Object element = cell.getElement();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
		if (element instanceof Executable) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
			Executable exe = (Executable) element;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
			String cellText = exe.getName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    61
			if (cell.getColumnIndex() == 1)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    62
				cellText = exe.getProject().getName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    63
			else if (cell.getColumnIndex() == 2)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    64
				cellText = exe.getPath().toOSString();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    65
			else if (cell.getColumnIndex() == 3) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    66
				cellText = ""; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    67
				IPath path = exe.getPath();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    68
				if (path != null && path.toFile().exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    69
					long fileLength = path.toFile().length();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    70
					cellText = Long.toString(fileLength);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    71
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    72
				cell.setImage(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    73
			} else if (cell.getColumnIndex() == 4) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    74
				cellText = ""; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    75
				IPath path = exe.getPath();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    76
				if (path != null && path.toFile().exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    77
					long modified = path.toFile().lastModified();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    78
					cellText = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date(modified));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    79
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    80
				cell.setImage(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    81
			} else if (cell.getColumnIndex() == 5) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    82
				cellText = ""; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    83
				String fileExtension = exe.getPath().getFileExtension();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    84
				if (fileExtension != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    85
					cellText = fileExtension;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    86
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    87
			cell.setText(cellText);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    88
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    89
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    90
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    91
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    92
	public String getText(Object element) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    93
		if (element instanceof Executable) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    94
			return ((Executable) element).getName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    95
		} else
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    96
			return super.getText(element);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    97
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    98
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    99
	public Object[] getChildren(Object parentElement) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   100
		return new Object[] {};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   101
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   102
60
3982fab6369e fixed executables view merge problems - bug #'s 9562, 9568, 9571.
wpaul
parents: 52
diff changeset
   103
}