Differenze tra le versioni di "Programmazione:Java/Eclipse RCP/Disattivare il ridimensionamento delle viste"
Riga 3: | Riga 3: | ||
<code java> | <code java> | ||
− | import org.eclipse.ui. | + | import org.eclipse.swt.widgets.Shell; |
+ | import org.eclipse.ui.IPerspectiveDescriptor; | ||
+ | import org.eclipse.ui.IPerspectiveListener; | ||
import org.eclipse.ui.IWorkbenchPage; | import org.eclipse.ui.IWorkbenchPage; | ||
+ | import org.eclipse.ui.IWorkbenchWindow; | ||
import org.eclipse.ui.PlatformUI; | import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.internal.WorkbenchPage; | import org.eclipse.ui.internal.WorkbenchPage; | ||
− | + | @SuppressWarnings("restriction") | |
− | + | public class PerspectiveManager { | |
− | + | private String currentPerspective = ""; | |
+ | |||
+ | private PerspectiveManager(IWorkbenchWindow w) { | ||
+ | w.addPerspectiveListener(new IPerspectiveListener() { | ||
+ | public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { | ||
+ | if (PlatformUI.getWorkbench().getDisplay().getActiveShell() != null) { | ||
+ | PlatformUI.getWorkbench().getDisplay().getActiveShell().setImage(perspective.getImageDescriptor().createImage()); | ||
+ | PlatformUI.getWorkbench().getDisplay().getActiveShell().setText(perspective.getLabel()); | ||
+ | } else { | ||
+ | Shell[] shells = PlatformUI.getWorkbench().getDisplay().getShells(); | ||
+ | if (shells.length > 0) { | ||
+ | shells[shells.length - 1].setImage(perspective.getImageDescriptor().createImage()); | ||
+ | shells[shells.length - 1].setText(perspective.getLabel()); | ||
+ | } | ||
+ | } | ||
+ | if (!currentPerspective.equals(perspective.getId())) { | ||
+ | currentPerspective = perspective.getId(); | ||
+ | TopRenderRegistry tr_reg = TopRenderRegistry.getInstance(); | ||
+ | BaseApplicationWorkbenchWindowAdvisor.changeTop(tr_reg.getRender(perspective.getId())); | ||
+ | BaseApplicationWorkbenchWindowAdvisor.extendPerspective(perspective.getId()); | ||
+ | } | ||
+ | PerspectiveExtensionRegistry pe_reg = PerspectiveExtensionRegistry.getInstance(); | ||
+ | PerspectiveExtension pe = pe_reg.getRender(currentPerspective); | ||
+ | if (pe.fixView) { | ||
+ | ((WorkbenchPage) page).getPerspectivePresentation().getLayout().disposeSashes(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public void perspectiveChanged(IWorkbenchPage arg0, IPerspectiveDescriptor arg1, String arg2) { | ||
+ | } | ||
+ | }); | ||
} | } | ||
− | public void | + | private static PerspectiveManager self; |
+ | |||
+ | public static void initialize(IWorkbenchWindow w) { | ||
+ | if (self == null) { | ||
+ | self = new PerspectiveManager(w); | ||
+ | } | ||
} | } | ||
− | public | + | public static PerspectiveManager getInstance(IWorkbenchWindow w) { |
+ | if (self == null) { | ||
+ | self = new PerspectiveManager(w); | ||
+ | } | ||
+ | return self; | ||
} | } | ||
− | } | + | } |
</code> | </code> |
Versione delle 12:50, 20 lug 2007
Disattivare il ridimensionamento delle viste
Per disattivare il ridimensionamento delle viste, come si può intuire, è fattibile solo infilandosi in mezzo al codice internal di eclipse
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPage;
@SuppressWarnings("restriction")
public class PerspectiveManager {
private String currentPerspective = "";
private PerspectiveManager(IWorkbenchWindow w) {
w.addPerspectiveListener(new IPerspectiveListener() {
public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
if (PlatformUI.getWorkbench().getDisplay().getActiveShell() != null) {
PlatformUI.getWorkbench().getDisplay().getActiveShell().setImage(perspective.getImageDescriptor().createImage());
PlatformUI.getWorkbench().getDisplay().getActiveShell().setText(perspective.getLabel());
} else {
Shell[] shells = PlatformUI.getWorkbench().getDisplay().getShells();
if (shells.length > 0) {
shells[shells.length - 1].setImage(perspective.getImageDescriptor().createImage());
shells[shells.length - 1].setText(perspective.getLabel());
}
}
if (!currentPerspective.equals(perspective.getId())) {
currentPerspective = perspective.getId();
TopRenderRegistry tr_reg = TopRenderRegistry.getInstance();
BaseApplicationWorkbenchWindowAdvisor.changeTop(tr_reg.getRender(perspective.getId()));
BaseApplicationWorkbenchWindowAdvisor.extendPerspective(perspective.getId());
}
PerspectiveExtensionRegistry pe_reg = PerspectiveExtensionRegistry.getInstance();
PerspectiveExtension pe = pe_reg.getRender(currentPerspective);
if (pe.fixView) {
((WorkbenchPage) page).getPerspectivePresentation().getLayout().disposeSashes();
}
}
public void perspectiveChanged(IWorkbenchPage arg0, IPerspectiveDescriptor arg1, String arg2) {
}
});
}
private static PerspectiveManager self;
public static void initialize(IWorkbenchWindow w) {
if (self == null) {
self = new PerspectiveManager(w);
}
}
public static PerspectiveManager getInstance(IWorkbenchWindow w) {
if (self == null) {
self = new PerspectiveManager(w);
}
return self;
}
}