Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.ant.internal.ui.preferences;
 
 
 import java.io.File;
 import java.util.List;
 
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.custom.BusyIndicator;
 import  org.eclipse.swt.events.FocusAdapter;
 import  org.eclipse.swt.events.FocusEvent;
 import  org.eclipse.swt.events.KeyAdapter;
 import  org.eclipse.swt.events.KeyEvent;
 import  org.eclipse.swt.events.ModifyEvent;
 import  org.eclipse.swt.events.ModifyListener;
 import  org.eclipse.swt.events.SelectionAdapter;
 import  org.eclipse.swt.events.SelectionEvent;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.layout.GridLayout;
 import  org.eclipse.swt.widgets.Combo;
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
 import  org.eclipse.swt.widgets.Label;
 import  org.eclipse.swt.widgets.Shell;
 import  org.eclipse.swt.widgets.Text;
 
 public class AddCustomDialog extends StatusDialog {
 	
 	
 	//A boolean to indicate if the user has typed anything
 	private boolean entryChanged = false;
 
 	private Combo sourceNameField;
 	private List libraryEntries;
 	private List existingNames;
 	
 	private String noNameErrorMsg;
 	
 	
 	private Text nameField;
 	
 	private String name=""//$NON-NLS-1$
 	private IAntClasspathEntry librarynull;
 	private String className=""//$NON-NLS-1$
 	
 	private boolean editingfalse;
 	
 	private String helpContext;

Creates a new dialog with the given shell and title.
 
 	public AddCustomDialog(Shell parentList libraryEntriesList existingNamesString helpContext) {
 		super(parent);
 		this. = libraryEntries;
 		this.existingNames;
		this.helpContext;
		setShellStyle(getShellStyle() | SWT.RESIZE);
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createDialogArea(Composite parent) {
		Composite topComposite= (Composite) super.createDialogArea(parent);
		topComposite.setSize(topComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		Composite topGroup = new Composite(topComposite, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.marginHeight= 0;
		layout.marginWidth= 0;
		topGroup.setLayout(layout);
		topGroup.setFont(topComposite.getFont());
		topGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
        
		createNameGroup(topGroup);
		if ( != null) {
		}
		return topComposite;
	}
	private void createNameGroup(Composite topComposite) {		
		Label label = new Label(topComposite, SWT.NONE);
		label.setFont(topComposite.getFont());
		 = new Text(topComposite, SWT.BORDER);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		.setLayoutData(data);
		.setFont(topComposite.getFont());
		.setText();
		.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
			}
		});
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
	 */
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell);
	}

Clears the cached structure provider after first finalizing it properly.
	private void clearProviderCache() {
		if ( != null) {
			 = null;
		}
	}

Attempts to close the passed zip file, and answers a boolean indicating success.
	private boolean closeZipFile(ZipFile file) {
		try {
			file.close();
catch (IOException e) {
			return false;
		}
		return true;
	}

Create the group for creating the root directory
	private void createRootDirectoryGroup(Composite parent) {
		Label groupLabel = new Label(parent, SWT.NONE);
		groupLabel.setFont(parent.getFont());
		// source name entry field
		 = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
		.setLayoutData(data);
		.setFont(parent.getFont());
		.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			}
		});
		while (libraries.hasNext()) {
			ClasspathEntry entry = (ClasspathEntrylibraries.next();
		}
		.addKeyListener(new KeyAdapter() {
			/*
			 * @see KeyListener.keyPressed
			 */
			public void keyPressed(KeyEvent e) {
				//If there has been a key pressed then mark as dirty
				 = true;
			}
		});
		.addFocusListener(new FocusAdapter() {
			/*
			 * @see FocusListener.focusLost(FocusEvent)
			 */
			public void focusLost(FocusEvent e) {
				//Clear the flag to prevent constant update
				if () {
					 = false;
				}
			}
		});
	}

Update the receiver from the source name field.
	private void updateFromSourceField(){
	}


Check the field values and display a message in the status if needed.
	private void updateStatus() {
		StatusInfo statusnew StatusInfo();
		String customName.getText().trim();
		if (customName.length() == 0) {
else if (!){
			while (names.hasNext()) {
				String aName = (Stringnames.next();
				if(aName.equals(customName)) {
					status.setError(MessageFormat.format(new String[]{customName}));
					updateStatus(status);
					return;
				}
			}
		}
		updateStatus(status);
	}


Sets the source name of the import to be the supplied path. Adds the name of the path to the list of items in the source combo and selects it.

Parameters:
path the path to be added
	private void setSourceName(String path) {
		if (path.length() > 0) {
			String[] currentItems = this..getItems();
			int selectionIndex = -1;
			for (int i = 0; i < currentItems.lengthi++) {
				if (currentItems[i].equals(path)) {
					selectionIndex = i;
					break;
				}
			}
			if (selectionIndex < 0) {
				int oldLength = currentItems.length;
				String[] newItems = new String[oldLength + 1];
				System.arraycopy(currentItems, 0, newItems, 0, oldLength);
				newItems[oldLength] = path;
				this..setItems(newItems);
				selectionIndex = oldLength;
			}
			this..select(selectionIndex);
		}
	}
	/*
	* Create the file selection widget
	*/
	private void createFileSelectionGroup(Composite parent) {
		//Just create with a dummy root.
		FileSystemElement dummyRootnew FileSystemElement("Dummy"nulltrue); //$NON-NLS-1$
		this. = new TreeAndListGroup(parentdummyRoot
				new WorkbenchLabelProvider(), SWT.NONE, 400, 150, false);
			public void selectionChanged(SelectionChangedEvent event) {
			}
		};
		this..setListSorter(comparator);
			public void doubleClick(DoubleClickEvent event) {
				if (getButton(.).isEnabled()) {
				}
			}
		});
	}

Returns whether the specified source currently exists and is valid (ie.- proper format)
	protected boolean ensureSourceIsValid() {
		ZipFile specifiedFile = getSpecifiedSourceFile();
		if (specifiedFile == null){
			return false;
		}
		return closeZipFile(specifiedFile);
	}
Answer the root FileSystemElement that represents the contents of the currently-specified .zip file. If this FileSystemElement is not currently defined then create and return it.
		IImportStructureProvider providernull;
		if (sourceFile == null) {
			File filenew File(.getText());
			if (file.exists()) {
				elementselectFiles(fileprovider);
else {
			//zip file set as location
			provider = getStructureProvider(sourceFile);
			elementselectFiles(((ZipFileStructureProvider)provider).getRoot(), provider);
		}
		this. = provider;
		return element;
	}

Invokes a file selection operation using the specified file system and structure provider. If the user specifies files then this selection is cached for later retrieval and is returned.
	private MinimizedFileSystemElement selectFiles(final Object rootFileSystemObjectfinal IImportStructureProvider structureProvider) {
		BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
			public void run() {
				//Create the root element from the supplied file system object
				results[0] = createRootElement(rootFileSystemObjectstructureProvider);
			}
		});
		return results[0];
	}

Creates and returns a MinimizedFileSystemElement if the specified file system object merits one.
		boolean isContainer = provider.isFolder(fileSystemObject);
		String elementLabel = provider.getLabel(fileSystemObject);
		// Use an empty label so that display of the element's full name
		// doesn't include a confusing label
			new MinimizedFileSystemElement(""nulltrue);//$NON-NLS-1$
		dummyParent.setPopulated();
			new MinimizedFileSystemElement(elementLabeldummyParentisContainer);
		result.setFileSystemObject(fileSystemObject);
		//Get the files for the element so as to build the first level
		result.getFiles(provider);
		return dummyParent;
	}

Answer a handle to the zip file currently specified as being the source. Return null if this file does not exist or is not of valid format.
		try {
			String expanded = .getText();
			expanded= VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(expanded);
			return new ZipFile(expanded);
catch (ZipException e) {
			StatusInfo statusnew StatusInfo();
			updateStatus(status);
catch (IOException e) {
			StatusInfo statusnew StatusInfo();
			updateStatus(status);
catch (CoreException e) {
			StatusInfo statusnew StatusInfo();
			updateStatus(status);
		}
		.setFocus();
		return null;
	}
Returns a structure provider for the specified zip file.
		if ( == null) {
else if (!.getZipFile().getName().equals(targetZip.getName())) {
			// ie.- new value, so finalize & remove old value
else if (!.getZipFile().equals(targetZip)) {
			closeZipFile(targetZip); // ie.- duplicate handle to same .zip
		}
	}

Repopulate the view based on the currently entered directory.
	private void resetSelection() {
		.setRoot(currentRoot);
		if (.length() != 0) {
			StringTokenizer tokenizernew StringTokenizer("."); //$NON-NLS-1$
			selectClass(currentRoottokenizer);
		}
	}
	private void selectClass(MinimizedFileSystemElement currentParentStringTokenizer tokenizer) {
		if (!tokenizer.hasMoreTokens()) {
			return;
		}
		List folderscurrentParent.getFolders();
		if (folders.size() == 1) {
			if (element.getLabel(null).equals("/")) { //$NON-NLS-1$
				selectClass(elementtokenizer);
				return;
			}
		}
		String currentNametokenizer.nextToken();
		if (tokenizer.hasMoreTokens()) {
			Iterator allFoldersfolders.iterator();
			while (allFolders.hasNext()) {
				if (folder.getLabel(null).equals(currentName)) {
					selectClass(foldertokenizer);
					return;
				}
			}	
else {
			List filescurrentParent.getFiles();
			Iterator iterfiles.iterator();
			while (iter.hasNext()) {
				if (file.getLabel(null).equals(currentName + ".class")) { //$NON-NLS-1$
					return;
				}
			}
		}
	}

Returns a content provider for MinimizedFileSystemElements that returns only files as children.
		return new WorkbenchContentProvider() {
			public Object[] getChildren(Object o) {
				if (o instanceof MinimizedFileSystemElement) {
					return element.getFiles().toArray();
				}
				return new Object[0];
			}
		};
	}

Returns a content provider for MinimizedFileSystemElements that returns only folders as children.
		return new WorkbenchContentProvider() {
			public Object[] getChildren(Object o) {
				if (o instanceof MinimizedFileSystemElement) {
				}
				return new Object[0];
			}
			public boolean hasChildren(Object o) {
				if (o instanceof MinimizedFileSystemElement) {
					if (element.isPopulated()) {
						return getChildren(element).length > 0;
					}
					//If we have not populated then wait until asked
					return true;
				}
				return false;
			}
		};
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
	 */
	protected void cancelPressed() {
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
	protected void okPressed() {
		.getText().trim();
		if (element == null) {
			super.okPressed();
			return;
		}
		Object fileelement.getFileSystemObject();
		if (file instanceof ZipEntry) {
else {
			IPath classPathnew Path();
			IPath libraryPathnew Path(.getEntryURL().getPath());
			int matchingclassPath.matchingFirstSegments(libraryPath);
			classPathclassPath.removeFirstSegments(matching);
			classPathclassPath.setDevice(null);
			classPath.toString();
		}
		int index.lastIndexOf('.');
		.replace('/''.'); 
		super.okPressed();
	}
	protected String getName() {
		return ;
	}
	protected void setName(String name) {
		this.name;
	protected void setLibraryEntry(IAntClasspathEntry library) {
		this.library;
		true;
	}
		return this.;
	}
	protected String getClassName() {
		return ;
	}
	protected void setClassName(String className) {
		this.className;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.window.Window#create()
	 */
	public void create() {
		super.create();
		getButton(.).setEnabled(!( == null));
	}
	protected void setAlreadyExistsErrorMsg(String alreadyExistsErrorMsg) {
		this. = alreadyExistsErrorMsg;
	}
	protected void setNoNameErrorMsg(String noNameErrorMsg) {
		this. = noNameErrorMsg;
	}
New to GrepCode? Check out our FAQ X