⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 albumselectionpage.java

📁 eclise rcp 项目,是非常好的学习源码
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2007 Siemens AG
 * 
 * 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:
 *    Kai T鰀ter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.wizards;

import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
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.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;

import com.siemens.ct.mp3m.model.logical.Album;
import com.siemens.ct.mp3m.model.logical.Artist;
import com.siemens.ct.mp3m.model.logical.Artists;

/**
 * A wizard page for selcting the artist and the album to rename.
 * 
 * @author Kai Toedter
 * @author $LastChangedBy: toedter_k $
 * @version $LastChangedDate: 2007-02-22 10:13:57 +0100 (Do, 22 Feb 2007) $
 * @version $LastChangedRevision: 469 $
 * 
 */
public class AlbumSelectionPage extends WizardPage implements Listener {

	private IStatus artistError = new Status(IStatus.ERROR, "not_used", 0,
			"Please select an artist.", null);

	private IStatus albumError = new Status(IStatus.ERROR, "not_used", 0,
			"Please select an album.", null);

	private IStatus ok = new Status(IStatus.OK, "not_used", 0, Messages.getString("AlbumSelectionPage.description"), null);

	private Combo artistsCombo;
	private Combo albumsCombo;
	private AlbumWizardModel model;

	public AlbumSelectionPage(AlbumWizardModel model) {
		super("");
		this.model = model;
		setTitle(Messages.getString("AlbumSelectionPage.title")); //$NON-NLS-1$
		setDescription(Messages.getString("AlbumSelectionPage.description")); //$NON-NLS-1$
	}

	public void createControl(Composite parent) {
		// create the composite to hold the widgets
		Composite composite = new Composite(parent, SWT.NONE);

		// create the desired layout for this wizard page
		GridLayout gl = new GridLayout(2, false);
		composite.setLayout(gl);

		// artist
		new Label(composite, SWT.NONE).setText(Messages.getString("AlbumSelectionPage.artist")); //$NON-NLS-1$
		artistsCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
		artistsCombo.addListener(SWT.Selection, this);
		Artist[] artists = Artists.getArtists();
		for (int i = 0; i < artists.length; i++) {
			artistsCombo.add(artists[i].getName());
		}
		artistsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		// album
		new Label(composite, SWT.NONE).setText(Messages.getString("AlbumSelectionPage.albums")); //$NON-NLS-1$
		albumsCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
		albumsCombo.addListener(SWT.Selection, this);
		albumsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		// set the composite as the control for this page
		setControl(composite);

	}

	public IStatus checkStatus(boolean applyToStatusline) {
		IStatus status = ok;
		if (artistsCombo.getSelectionIndex() == -1
				|| artistsCombo.getItem(artistsCombo.getSelectionIndex()).length() == 0) {
			status = artistError;
		} else if (albumsCombo.getSelectionIndex() == -1
				|| albumsCombo.getItem(albumsCombo.getSelectionIndex()).length() == 0) {
			status = albumError;
		}
		if (applyToStatusline)
			StatusUtil.applyToStatusLine(this, status);
		
		return status;
	}

	public boolean canFlipToNextPage() {
		if (checkStatus(false).isOK())
			return true;
		return false;
	}

	public void handleEvent(Event event) {
		if (event.widget == artistsCombo) {
			if (artistsCombo.getSelectionIndex() >= 0) {
				String selectedArtist = artistsCombo.getItem(artistsCombo.getSelectionIndex());
				Artist[] artists = Artists.getArtists();
				for (Artist artist : artists) {
					if (selectedArtist.equals(artist.getName())) {
						albumsCombo.removeAll();
						List<Album> albums = artist.getAlbums();
						for (Album album : albums) {
							albumsCombo.add(album.getName());
						}
						break;
					}
				}
				model.setArtist(selectedArtist);
			}
		} else if (event.widget == albumsCombo) {
			if (albumsCombo.getSelectionIndex() >= 0) {
				String selectedAlbum = albumsCombo.getItem(albumsCombo.getSelectionIndex());
				model.setOldName(selectedAlbum);
			}
		}
		checkStatus(true);
		getWizard().getContainer().updateButtons();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -